Nathanael
Nathanael

Reputation: 7173

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?

Upvotes: 6

Views: 5333

Answers (1)

Nathanael
Nathanael

Reputation: 7173

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

Upvotes: 2

Related Questions