|
 |
|
สอบถามเรื่องการ Download file จาก host [PHP] รบกวนจริงๆครับอยากจะปิดงานก่อนสงกรานต์ |
|
 |
|
|
 |
 |
|
คือตอนนี้อัพโหลดขึ้นไปเก็บไว้ได้แล้ว แต่ว่าเวลาจะดาวน์มันลงมาไม่สำเร็จครับ เท่าที่ดูเหมือนว่ามันจะหาไฟล์ตัวนั้นเจอ แต่พอคลิก open กลับแสดงหน้าจอเว็บเพจที่แสดงรายการดาวน์โหลด ไม่แสดงข้อมูลที่อยู่ในไฟล์ต้นฉบับ รบกวนทีครับ
Code (PHP)
//ถ้ากดปุ่ม upload now จะแสดงหน้า อัพโหลด
if($_POST['import']){
echo'<p>';
$convert_size = number_format(($_FILES["file_1"]["size"]/1024),1)." KB";
copy($_FILES["file_1"]["tmp_name"],"FileUpload/".$_FILES["file_1"]["name"]);
$userfile_name = $_FILES["file_1"]['name']; // file name
$userfile_tmp = "FileUpload/".$_FILES["file_1"]['name']; // actual location
$userfile_size = $_FILES["file_1"]['size']; // file size
$userfile_type = $_FILES["file_1"]['type']; // mime type of file determined by php
$userfile_error = $_FILES["file_1"]['error']; // any error!. get reason here
$date1 = date("Y-m-d H:i:s");
$sql_upload = "insert into asmt_file_upload(FileDescription,FileName,FileType,FileSize,FileExtension,FilePath,FileUploadBy,FileUploadDate,Supplier) values('$_POST[file_name]','$userfile_name','$_POST[file_type]','$convert_size','$userfile_type','$userfile_tmp','$_SESSION[name]','$date1','$_POST[sup_ID]')";
$query_upload = mysql_query($sql_upload)or die(mysql_error());
if($query_upload){
echo'<script>alert("COMPLETE :: Upload Successful!");</script>';
}
}
//ถ้ากดปุ่ม download_file จะแสดงหน้าจอการ download
if($_POST['download_file']){
echo'<p>';
echo'<form action="" method="post" enctype="multipart/form-data">';
echo'<table width="100%" align="center">';
echo'<tr bgcolor="lightblue">';
echo'<td align="center">Description File</td>';
echo'<td align="center">File Name</td>';
echo'<td align="center">File Group</td>';
echo'<td align="center">File Size</td>';
echo'<td align="center">Date Uploaded</td>';
echo'<td align="center">Download</td>';
echo'</tr>';
$sql_pull_data = "select * from asmt_file_upload where Supplier = '$_SESSION[me]' order by FileUploadDate desc";
$query_pull_data = mysql_query($sql_pull_data)or die(mysql_error());
while($result_pull_data = mysql_fetch_array($query_pull_data)){
echo'<tr>';
echo'<td>'.$result_pull_data['FileDescription'].'</td>';
echo'<td>'.$result_pull_data['FileName'].'</td>';
echo'<td align="center">'.$result_pull_data['FileType'].'</td>';
echo'<td align="center">'.$result_pull_data['FileSize'].'</td>';
echo'<td align="center">'.$result_pull_data['FileUploadDate'].'</td>';
echo'<td align="center"><button name="dl" value="'.$result_pull_data['FileName'].'"><img src="images/download.jpg" width="25" height="25"></button></td>';
echo'</tr>';
}
echo'</table>';
echo'</form>';
}
//ถ้ากดปุ่ม dl รูป download
if($_POST['dl']){
$path = 'FileUpload';
$realpath = $path .'/'.$_POST['dl'];
$filename = $realpath;
// $filename = realpath($filename);
$file_extension = strtolower(substr(strrchr($filename,"."),1));
switch ($file_extension) {
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpe": case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
if (!file_exists($filename)) {
die("NO FILE HERE");
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: ".$ctype);
header("Content-Disposition: attachment; filename=".basename($filename).";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".@filesize($filename));
set_time_limit(0);
@readfile($filename) or die("File not found.");
}
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2011-04-09 09:49:23 |
By :
chubichane |
View :
1192 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยผมหน่อยครับ ใครพอทราบบ้างเอ่ย...
|
 |
 |
 |
 |
Date :
2011-04-09 10:59:38 |
By :
chubichane |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|