简体   繁体   中英

PHP file upload validation

My php upload script works great and is validated for everything from file type to size except if no file exists. You can just hit the submit button and it will send blank data to the upload script. I was trying this:

if (!is_uploaded_file($HTTP_POST_FILES['ufile1']['name']))
{
        header("location:../index.php?code=no_file");
}

It won't work :(

Any way of getting this to work? -mike

Check the error code:

http://www.php.net/manual/en/features.file-upload.errors.php

if ($_FILES['ufile1']['error'] == UPLOAD_ERR_NO_FILE) { /* no file */ }

Note that you should already be checking the error code to make sure that it's UPLOAD_ERR_OK on files that you actually acccept.

Also, $HTTP_POST_FILES is deprecated in favour of $_FILES these days. That signifies to me that you probably want to find a newer tutorial.

我使用的是最后的file_exists($name_of_submitted_file)函数,以查看文件是否已成功上传。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM