Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php://input for file upload?

I am attempting to upload a video file in chunks using PHP. (and we all know how finnicky PHP is with this) Below is my test code:

echo "<form action='' method='post' enctype='multipart/form-data'>";
echo "<input name='video' type='file' />";
echo "<input type='submit' value='UPLOAD' />";
echo "</form>";

if (isset($_POST['video']))
{
    $putdata = fopen("php://input", "r");
    $fp = fopen("assets/video/test.mp4", "w");

    while ($data = fread($putdata, 1024))
    {
        echo $data;
        fwrite($fp, $data);
    }

    echo "<h1>DONE! (hopefully)</h1>";

    fclose($fp);
    fclose($putdata);
}

When I echo $data;, I don't get the contents of the file--instead, I only get video=video.mp4, with video.mp4 being the name of the file I attempted to upload. What's going on? :( How do I get the actual file's contents?

like image 947
Nathanael Avatar asked Jun 12 '12 17:06

Nathanael


People also ask

How can get upload file name in PHP?

In PHP, we can access the actual name of the file which we are uploading by keyword $_FILES[“file”][“name”]. The $_FILES is the by default keyword in PHP to access the details of files that we uploaded.

Which function is used to upload a file in PHP?

enctype="multipart/form-data": This value refers to the content type of the files that will be accepted for uploading. It also indicates the type of encoding that the PHP script will use for uploading. The multipart/form-data value enables us to upload files using the POST method.

Where does PHP store uploaded files?

php stores all temporary files, that includes uploaded files, in the temporary files directory as specified in the php. ini. Note that for uploads, those files might be removed as soon as the script the file was uploaded to was terminated (so unless you delay that script, you probably won't see the uploaded file).

Which array is used for file uploading in PHP?

PHP | $_FILES Array (HTTP File Upload variables)


1 Answers

Client-side libraries should be used for chunked uploads like this, such as PLUpload.

like image 65
Nathanael Avatar answered Sep 30 '22 18:09

Nathanael