10/10/2018, 10:35
Giúp em về cách upload file trong php
Các Pác coi giúp em dùm đoạn code này sai chỗ nào và sữa lại dùm em luôn thanks các Pác!
code:
<?php
$upload_dir = "../upload/";
$filename = isset($_POST['file'])?$_POST['file']:';
if ( !preg_match('/^[a-z0-9\_-][a-z0-9\_-. ]*$/i', $filename)|| !is_file($upload_dir.$filename) || !is_readable($upload_dir.$filename) ) {
echo "Loi: Ten file khong hop le hoac file khong ton tai!";
exit(-1);
} //end if
$fp = fopen($upload_dir.$filename, "rb");
header('Content-type: application/octet-stream');
header('Content-disposition: attachment; filename="'.$filename.'"');
header('Content-length: ' . filesize($upload_dir.$filename));
fpassthru($fp);
fclose($fp);
?>
[=========> Bổ sung bài viết <=========]
<form method="POST" enctype="multipart/form-data" action="process_upload.php">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
<input type="file" name="file_upload" size="20">
<input type="submit" value="Upload">
</form>
code:
<?php
$upload_dir = "../upload/";
$filename = isset($_POST['file'])?$_POST['file']:';
if ( !preg_match('/^[a-z0-9\_-][a-z0-9\_-. ]*$/i', $filename)|| !is_file($upload_dir.$filename) || !is_readable($upload_dir.$filename) ) {
echo "Loi: Ten file khong hop le hoac file khong ton tai!";
exit(-1);
} //end if
$fp = fopen($upload_dir.$filename, "rb");
header('Content-type: application/octet-stream');
header('Content-disposition: attachment; filename="'.$filename.'"');
header('Content-length: ' . filesize($upload_dir.$filename));
fpassthru($fp);
fclose($fp);
?>
[=========> Bổ sung bài viết <=========]
<form method="POST" enctype="multipart/form-data" action="process_upload.php">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
<input type="file" name="file_upload" size="20">
<input type="submit" value="Upload">
</form>
Bài liên quan
<?php
if ( $_SERVER["REQUEST_METHOD"] != "POST" )
{
echo "method POST";
exit(-1);
}
if ( $_FILES["file_upload"]["size"] > $MAX_FILE_SIZE )
{
echo "file lon";
exit(-1);
}
if ( !isset($_FILES["file_upload"]["error"]) || $_FILES["file_upload"]["error"] != 0 )
{
echo "loi xay ra";
$temp = preg_split('/[\/\\\\]+/', $_FILES["file_upload"]["name"]);
$filename = $temp[count($temp)-1];
$upload_dir = "C:\AppServ\www\potay\upload";
$upload_file = $upload_dir . $filename;
if ( move_uploaded_file($_FILES['file_upload']['tmp_name'],$upload_file))
{
echo "OK file upload";
}
else
{
echo "upload sai";
}
}
?>
tại sao em cài thằng smtp và cấu hình smtp rùi nhưng sao lại ko gữi đc hả anh?