api-php How to determine the file upload with put method?

Source: Internet
Author: User
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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.