php 上传文件tmp name,PHP上传文件tmp_name为空定位为上传大小导致的问题

I have this problem on my file upload. I try to upload my PDF file while checking on validation the TMP_NAME is empty and when I check on $_FILES['document_attach']['error'] the value is 1 so meaning there's an error.

But when I try to upload other PDF file it's successfully uploaded. Why is other PDF file not?

HTML

Title

File

PHP

if(isset($_POST['submit'])){

$title = $_POST['title'];

$filename = $_FILES['document_attach']['name'];

$target_dir = "../eqms_files/";

$maxSize = 5000000;

if(!empty($title)){

if(is_uploaded_file($_FILES['document_attach']['tmp_name'])){

if ($_FILES['document_attach']['size'] > $maxSize) {

echo "File must be: ' . $maxSize . '";

} else {

$result = move_uploaded_file($_FILES['document_attach']['tmp_name'], $target_dir . $filename);

mysqli_query($con, "INSERT into internal_audit (id, title, file) VALUES ('', '".$title."', '".$filename."')");

echo "Successfully Uploaded";

}

}else

echo "Error Uploading try again later";

}else

echo "Document Title is empty";

}

# Answer 1

4d350fd91e33782268f371d7edaa8a76.png

I just check the max size in phpinfo();

Then check if php.ini is loaded

$inipath = php_ini_loaded_file();

if ($inipath) {

echo 'Loaded php.ini: ' . $inipath;

} else {

echo 'A php.ini file is not loaded';

}

Then Change the upload_max_filesize=2M to 8M

; Maximum allowed size for uploaded files.

upload_max_filesize = 8M

; Must be greater than or equal to upload_max_filesize

post_max_size = 8M

# Answer 2

var_dump($_FILES['file_flag']['tmp_name']); // file_flag file key

will return empty string

array (size=1)

'course_video' =>

array (size=5)

'name' => string 'fasdfasdfasdfsd.mp4' (length=19)

'type' => string '' (length=0)

'tmp_name' => string '' (length=0) <===== *** this point

'error' => int 1

'size' => int 0

This happen because WAMP server not accepting this much size to uploaded on server.

to avoid this we need to change php.ini file.

upload_max_filesize=100M (as per your need)

post_max_size = 100M (as per your need)

Mx9pu.png

bbKdt.png

hRFYA.png

finally restart server

u7Trl.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值