Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try not to read the whole file into memory before sending. curl IMHO supports reading the file itself before uploading and therefor should work inside the memory borders. See the following blog post for an example: <a href="http://dtbaker.com.au/random-bits/uploading-a-file-using-curl-in-php.html" rel="nofollow noreferrer">http://dtbaker.com.au/random-bits/uploading-a-file-using-curl-in-php.html</a></p> <p>I haven't worked with the youtube direct upload API yet but after a quick look I saw that this does not seem the be a normal html form file upload but a bit more complex data format. I am not sure whether you can do this with plain cURL without building the whole POST data in memory yourself.</p> <p>If you have this small memory limits (~4 MB of RAM) you could try building your own simple HTTP client on top of the streams API in PHP: Create a temporary file and write your POST request data into that file handle (using fwrite() for normal strings and stream_copy_to_stream() for direct file to file data transfer). When your request is ready, rewind your temporary file to the beginning and then copy that stream into the connection with the youtube http server (again using stream_copy_to_stream()).</p> <p>As the streams are copied in small chunks you should be able to do that with less then 4 MB of RAM, even for large files.</p> <p>EDIT:</p> <p>Following pseudo-php-code-mashup should be helpful ;)</p> <pre><code>$xmlAPIRequest = /* fill with the XML-API-Request */ $boundaryString = /* fill me with some random data */ // create temporary file handle $pdh = tmpfile(); fwrite($pdh, "--$boundaryString\r\n"); fwrite($pdh, "Content-Type: application/atom+xml; charset=UTF-8\r\n\r\n"); fwrite($pdh, $xmlAPIRequest."\r\n"); fwrite($pdh, "--$boundaryString\r\n"); fwrite($pdh, "Content-Type: &lt;video_content_type&gt;\r\nContent-Transfer-Encoding: binary\r\n\r\n"); $videoFile = fopen("/path/to/video", "r"); stream_copy_to_stream($videoFile, $pdh); fclose($videoFile); fwrite($pdh, "--$boundaryString--\r\n"); /* not quite sure, whether there needs to be another linebreak before the boundary string */ $info = fstat($pdh); rewind($pdh); $contentLength = $info['size']; $conn = fsockopen("hostname", 80); /* write http request to $conn and use $contentLength for Content-Length header */ /* after last header you put another line break to tell them that now the body follows */ // write post data from stream to stream stream_copy_to_stream($pdh, $conn); // ... process response... etc... </code></pre> <p>There are certainly a lot of bugs in this code but as it is only a short example I think we can live with that. ;)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload