الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

سؤال عن سكربت download

مغلق
بدأه zarzor_2010 في 1 يوليو 2006 · 1 رد · 507 مشاهدة · في منتدى تطوير المواقع بـ PHP
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

لقد قمت بعم سكربت PHP لعمل UPLOAD AND DOWNLOAD لملفات و لكن المشكلة عند التنزيل فانه يوم بتنزيل 0 BYTES و لا أعرف لماذا

DOWNLOADCODE:

$id = $_GET['id'];

$query = "select * from downloads where download_id = $id";

$link = mysql_query($query) or die ( mysql_error() );

$res = mysql_fetch_array($link);

$type = $res['type'];

$size = $res['size'];

$path = $res['path'];

$name = $res['name'];

$no = $res['no_of_download'];

//add one to the counter

$no ++ ;

$query = "update downloads set no_of_download = $no where download_id = $id";

mysql_query($query) or die ( mysql_error() );

//start downloading

header("Content-Disposition: attachment; filename=$name");

header("Content-length: $size");

header("Content-type: $type");

readfile($path);

#2

الكود به تحسين كثير، مثل:

* استعمال الكونتر يزيد من التحميل

* طريقة طرح الملف

* طريقة قراءة الملف يزيد الحمل على السرفر

الكود كذا يكون احسن:

$id = $_GET['id'];
$get_file = @mysql_query("SELECT `type`,`path`,`name`
			FROM `downloads` WHERE `download_id`='$id'") or die (mysql_error());
$file_info = @mysql_fetch_array($get_file);

//add one to the counter
$update_files = @mysql_query("UPDATE `downloads` SET `no_of_download`= no_of_download +1 
WHERE `download_id`='$id'") or die (mysql_error());

//start downloading
$file_link = $get_file['path'];
if(ini_get('zlib.output_compression')){
	@ini_set('zlib.output_compression', 'Off');
}
@header("Pragma: public"); // required
@header("Expires: 0");
@header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
@header("Cache-Control: private",false); // required for certain browsers 
@header("Content-Type: $get_file[type]");
@header("Content-Disposition: attachment; filename=".basename($file_link).";" );
@header("Content-Transfer-Encoding: binary");
@header("Content-Length: ".filesize($file_link)); 
// or header("Content-Length: $get_file[size]");

$image_file=fopen($file_link,"r");
while($contents = @fread($image_file,1048576)){
	echo $contents;
}
@mysql_close();
@fclose($file);
exit();

مع السلامة

هذا الموضوع مغلق.

مواضيع مشابهة