|
 |
|
บันทึกข้อมูลไม่ได้ กรณีไม่ได้แนบไฟล์ คำสั่ง PATHINFO_EXTENSION |
|
 |
|
|
 |
 |
|
ผมใช้คำสั่ง PATHINFO_EXTENSION ในการจำกัดสกุลไฟล์ ซึ่งถ้าแนบไฟล์ที่ตรงกับนามสกุลที่กำหนดจะทำงานได้ปกติ
แต่ว่าไม่สามารถบันทึกได้กรณีที่ไม่แนบไฟล์ครับ
จะเข้า echo"Your file extension must be zip,pdf,png,txt"; เสมอ
Code (PHP)
if(isset($_POST['save']))
{
$filename = $_FILES['myfile']['name'];
$destination = 'uploads/' . $filename;
$extension = pathinfo($filename,PATHINFO_EXTENSION);
$file = $_FILES['myfile']['tmp_name'];
$size = $_FILES['myfile']['size'];
if(!in_array ($extension,['zip','pdf','png','txt']))
{
echo"Your file extension must be zip,pdf,png,txt";
}
elseif($_FILES['myfile']['size'] > 100000000)
{
echo "file is too large" ;
}
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2020-06-08 12:06:17 |
By :
thedarkeye |
View :
1016 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 00
|