PDA

View Full Version : مشکل ابن کد



olampiad
سه شنبه 04 شهریور 1393, 22:40 عصر
سلام و خسته نباشید ب اساتید عزیز
به این کد من ی نگا بندازید




$ff=fopen("$id.txt",'w');
$ff="$id.txt";



من ی چنین فایلی دارم چ طور میتونم با رفش صفحه اون رو دانلود کنم.
می خوام مرور گر این فایل رو دانلود کنه.
چ طور مرورگر رو مجبور ب دانلود این فایل کنم.
ممنون

مهرداد سیف زاده
سه شنبه 04 شهریور 1393, 22:48 عصر
باید header رو ست کنید برای دانلود فایل
البته در مورد فایلهای txt تجربه ثابت کرده باید بصورت زیر کار کنید
یعنی ابتدا header رو آماده کنید برای دانلود فایل که اسم فایل هم در همون نوشته شده و دقیقا در یک خط بعدش محتوا فایل یا هر چیز دیگری رو رو echo کنید تا برای کاربر دانلود بشه


header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=filename.txt");


echo file_get_contents("$id.txt");

olampiad
چهارشنبه 05 شهریور 1393, 21:07 عصر
سلام و خسته نباشید
این کدی شما گفتید رو انجام دادم
به درستی کار میکنه
ولی محتوای فایل دانلود شده چیز دیگه ای هستش

این کد من هستش
من میخوام این داده هارو دانلود کنم.
ممنون





if(isset($_POST['idd'])){
$id=$_POST['id'];

mysql_connect('localhost','root','');
mysql_select_db('oe');
$jj=mysql_query("select * from `shift` where `user_id`='{$id}'");

$ff=fopen("$id.txt",'w');
$ff="$id.txt";
$curent=file_get_contents($ff);
while($dd=mysql_fetch_assoc($jj)){
$curent.='id=>'.$dd['id'];
$curent.='user_id=>'.$dd['user_id'];
$curent.='shoro=>'.$dd['shoro'];
$curent.='end=>'.$dd['end'];
$curent.='name=>'.$dd['name'] ;
}
file_put_contents($ff,$curent);

header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=$ff");
echo file_get_contents("$id.txt");

}

مهرداد سیف زاده
پنج شنبه 06 شهریور 1393, 07:33 صبح
خب دوست عزیز چرا دیگه file_pu_contents میکنید
همون متغیر رو بیارید پایین صفحه و مستقیما ‌echo کنید


if(isset($_POST['idd'])){
$id=$_POST['id'];

mysql_connect('localhost','root','');
mysql_select_db('oe');
$jj=mysql_query("select * from `shift` where `user_id`='{$id}'");


$ff="{$id}.txt";
$curent='';
while($dd=mysql_fetch_assoc($jj)){
$curent.='id=>'.$dd['id'];
$curent.='user_id=>'.$dd['user_id'];
$curent.='shoro=>'.$dd['shoro'];
$curent.='end=>'.$dd['end'];
$curent.='name=>'.$dd['name'] ;
}


header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=$ff");
echo $curent;

}


در واقع اگر قصد ذخیره دیتای اضافی روی هاست رو ندارید به این صورت عمل کنید. یعنی لازم هم نیست یک فایل txt روی هاست ذخیره بشه. متغیر رو مستقیما echo کنید که خودش به صورت فایل دانلود میشه.

olampiad
پنج شنبه 06 شهریور 1393, 16:10 عصر
سلام دوست عزیز
چیزی که من میخوام رو دانلود نمکنه و این رو تو فایل قرار میدهمیگردونه
ممنون






<!doctype html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Home</title>
<link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="/on/css/globaldf05.css?c=build-169" />
<link type='text/css' rel='stylesheet' href='/on/vendors/jquery-ui/jquery-ui-1.10.4.custom.mindf05.css?c=build-169' />

</head>

<body id="page-index" class="en">
<!-- header -->

<div id="header-wrap">
<div id="header">
<h1>
<img src="img/7s-logo-round.png" class="profile-avatar company-logo" />

<div class="company-meta ">
<a href="employers.html">
User
</a>
<div class="welcome-user">
user@mail.ex
</div>
</div>
<div class="clear">
</div>
</h1>

<div id="extra-options" class="btn-group btn-top-nav-controls">
<button type="button" class="btn dropdown-toggle" data-toggle="dropdown">
Account
<span class="caret">
</span>
</button>
<ul class="dropdown-menu pull-left" role="menu">
<li>
<a href="employers/settings.html">
<span class="glyphicon glyphicon-cog">
</span>
Settings
</a>
</li>
<li>
<a href="#logout">
<span class="glyphicon glyphicon-share">
</span>
Logout
</a>
</li>
</ul>
</div>

<ul id="main-nav" class="clearfix">

<li id="first-nav-item" class="selected">
<a href="/on/index.php?r=site/index">
<span class="inner">
home
</span>
</a>
</li>
<li >
<a href="/on/index.php?r=user/admin">
<span class="inner">
employees
</span>
</a>

</li>
<li >
<a href="/on/index.php?r=site/schedules">
<span class="inner">
schedules
</span>
</a>
</li>


<li >
<a href="/on/index.php?r=site/reports">
<span class="inner">
reports
</span>
</a>

</li>

</ul>

<div class="clear">
</div>

</div>
</div>
<div id="content">
id=>4user_id=>25shoro=>1408855259end=>1408855900name=>id=>5user_id=>25shoro=>1408855259end=>1408859000name=>
<!-- /#header -->

<!-- content -->
<div id="wrap">

<div id="content" class="reports index user-type-id-2">


<h2>Reports</h2>

<div id="reports-tabs"></div>

<script id="punch-variance" type="text/template">
<div class="report-info">
See the difference between hours scheduled and hours worked.
</div>

<form method="get" action="/accounts/reports/punch_variance" target="_blank">
<ol class="inline-form clearfix">
<li class="hours-wages-date-range">
<label>Date range</label>
<input type="text" name="from" class="from" value="2014-04-01" />
&nbsp; to &nbsp;
<input type="text" name="to" class="to" value="2014-04-30" />
</li>
<input type="hidden" name="location_id" value="6186" />
<li class="hours-wages-view-as">
<label>View as</label>
<select name="export" class="export">
<option value="csv">Excel (download)</option>
<option value="printable">Web (print)</option>
</select>
</li>
</ol>
<input type="submit" class="btn btn-success" value="Submit" />

</form>
</script>

<script id="worked-employee-hours-costs" type="text/template">
<div class="report-info">
Provides a detailed view of hours worked and wages.
</div>

<form method="get" action="/accounts/reports/worked_hours_costs" target="_blank">
<ol class="inline-form clearfix">
<li class="hours-wages-date-range">
<label>Date range</label>
<input type="text" name="from" class="from" value="2014-04-01" />
&nbsp; to &nbsp;
<input type="text" name="to" class="to" value="2014-04-30" />
</li>
<input type="hidden" name="location_id" value="6186" />
<li class="hours-wages-view-as">
<label>View as</label>
<select name="export" class="export">
<option value="csv">Excel (download)</option>
<option value="printable">Web (print)</option>
</select>
</li>
</ol>
<input type="submit" class="btn btn-success" value="Submit" />

</form>
</script>





<form method="post" action="" style="padding:20px;">

<ol class="inline-form clearfix">
<li style="">
<label>User</label>
<select name="id">
<option value="13">asdsd asdd</option>
<option value="15">sdasdasd asdasdsdsad</option>
<option value="17">asddas asdasdasdASsd</option>
<option value="20">mojtaba assaa</option>
<option value="22"> </option>
<option value="25">asd asd</option>
<option value="27"> </option>
<option value="28"> </option>
<option value="29"> </option>
<option value="30">asdasasdasd asd</option>


</select>
</li>
<input type="hidden" name="location_id" value="6186" />
</ol>
<input type="submit" name="idd" class="btn btn-success" value="Submit" />
</form>






</div><!-- content -->

<div class="clear"></div>

<div id="footer">
&copy; NSC 15
</div>
<!-- /#footer -->


</div>
<!-- /#content -->
</div>
<!-- /#wrap -->


</body>
</html>

olampiad
جمعه 07 شهریور 1393, 00:42 صبح
مشکلم حل نمیشه یکی کمک کنه
ممنون

مهرداد سیف زاده
جمعه 07 شهریور 1393, 07:08 صبح
این کدی که گذاشتید کجاش شبیه کد بالاست
این که داره یه کار دیگه انجام میده
بعدش هم آخر دانلود نمیکنه یا اشتباه دانلود میکنه؟
صفحه برای چی رفرش بشه. شاید شما جای دیگه هدر صفحه هدر رو دستکاری کردید