This upload is optional, if you have, together with the form of other fields are put to send over, then how to determine whether the upload file file?
My solution now is to read the put file into a temporary file, and then use Fiesize to determine the size of the file, if it is 0 when the description is not uploaded, but do not think it is safe to consult.
$handle = fopen('php://input', 'r'); $fp = fopen($tmp_as, "w+"); while ($data = fread($handle, 1024)) { fwrite($fp, $data); } fclose($fp); fclose($handle); if(filesize($tmp_as) && getimagesize($tmp_as)) {//文件是个图像,所以用了getimagesize函数 echo '//TODO 有文件上传并处理'; } else { echo '没有文件上传'; }
Reply content:
This upload is optional, if you have, together with the form of other fields are put to send over, then how to determine whether the upload file file?
My solution now is to read the put file into a temporary file, and then use Fiesize to determine the size of the file, if it is 0 when the description is not uploaded, but do not think it is safe to consult.
$handle = fopen('php://input', 'r'); $fp = fopen($tmp_as, "w+"); while ($data = fread($handle, 1024)) { fwrite($fp, $data); } fclose($fp); fclose($handle); if(filesize($tmp_as) && getimagesize($tmp_as)) {//文件是个图像,所以用了getimagesize函数 echo '//TODO 有文件上传并处理'; } else { echo '没有文件上传'; }
After the form is submitted, print $_files[' myfile ' Look, this is your uploaded picture (tmp end of the temporary file), need to move the file, with the Move_uploaded_file function