I have a problem with my project. I tried to upload a video to Picasa using a script from here, but the uploaded video file was larger than 600MB and I got this error:
PHP Fatal error: Allowed memory size of 1497366528 bytes exhausted (tried to allocate 681179924 bytes) in /path/to/file/test/picasa.php on line 119
I tried changing memory_limit = 128MB
to memory_limit = 1028MB
in php.ini
but it's still not working.
This is the function to upload:
function upload_file( $authHeader, $user_id, $album_id, $filename ) {
// Picasa album url
$albumUrl = "https://picasaweb.google.com/data/feed/api/user/$user_id/albumid/$album_id";
// Video file to upload
$imgName = $filename;
// Xml data
$ImgXml = '<entry xmlns="http://www.w3.org/2005/Atom">
<title>'.$filename.'</title>
<summary>'.$filename.'</summary>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/photos/2007#photo"/>
</entry>';
// Get the file size
$fileSize = filesize($imgName);
// Read the Video file, NOTE : THE ERROR FROM FREAD
$fh = fopen($imgName, 'rb');
$imgData = fread($fh, $fileSize);
fclose($fh);
// Count the file and data lengh
$dataLength = strlen($ImgXml) + $fileSize;
// Data for curl postpields
$data = "";
$data .= "\nMedia multipart posting\n";
$data .= "--P4CpLdIHZpYqNn7\n";
$data .= "Content-Type: application/atom+xml\n\n";
$data .= $ImgXml . "\n";
$data .= "--P4CpLdIHZpYqNn7\n";
$data .= "Content-Type: video/x-matroska\n\n";
$data .= $imgData . "\n";
$data .= "--P4CpLdIHZpYqNn7--";
$header = array(
'GData-Version: 2',
$authHeader,
'Content-Type: multipart/related; boundary=P4CpLdIHZpYqNn7;',
'Content-Length: ' . strlen($data),
'MIME-version: 1.0'
);
$return = "";
// Post the video with the data and header
$ch = curl_init($albumUrl);
$options = array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => $header
);
curl_setopt_array($ch, $options);
$return = curl_exec($ch);
curl_close($ch);
And I tried replacing
$fh = fopen($imgName, 'rb');
$imgData = fread($fh, $fileSize);
fclose($fh);
with this:
ob_start();
readfile($imgName);
$output = ob_get_contents();
ob_end_clean();
But it's still showing the same error. I tried to run the script via ssh, to no luck. Maybe it's because my VPS only has 2 GB of memory?
Then I read about curl and found --data-binary <data>
, I think maybe --data-binary <data>
could do this job.
My question is:
Are there alternatives to readfile
in php or is there another way to achieve this?
and
Can I upload that video to Picasa using curl as a linux command?