PHP Forums Archive

cURL upload won't work

Tags: upload, curl, file upload, filename must not be empty

robinbarton posted on 2009-05-30 22:01:13 #

A previous post of mine described an ftp_put issue that I later resolved. However, as Olaf suggested to me, now I am trying cURL because it turns out that my host has a size limit for that type of upload. I need to send files 50MB-100MB. (I did change all the parameters in php.ini, etc.)

Anyway, I'm brand new to cURL and have found many options but I'm not sure which all I need to use. Here is what I have and eventually it returns an error (but it's the same one my ftp_put returns, which is "2:filename cannot be empty".

 	
$ch = curl_init();
 	$localfile = $_FILES['VideoLocation']['tmp_name'];
 	$fp = fopen($localfile, 'r');
	$result = curl_setopt($ch, CURLOPT_URL, 'ftp://MyUserID:MyPassword@MyDomain.com/VideosApproved/'.$_FILES['VideoLocation']['name']);
//	$result = curl_setopt($ch, CURLOPT_USERPWD, 'MyUserID:MyPassword');
	$result = curl_setopt($ch, CURLOPT_PORT, 80);
 	$result = curl_setopt($ch, CURLOPT_INFILE, $fp);
 	$result = curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
 	$result = curl_setopt($ch, CURLOPT_UPLOAD, 1);
	$result = curl_setopt($ch, CURLOPT_VERBOSE, 1);
	$result = curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 	$result = curl_setopt($ch, CURLOPT_NOPROGRESS, 0); # to show progress meter ...
	$result = curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/6.0");
//the following line is where it just goes and goes and finally quits after about 20 minutes
 	$response = curl_exec ($ch);		//Execute the session
 	$error_no = curl_errno($ch);
	$error_msg = curl_error($ch);
 	curl_close ($ch);					//Close the cURL session
        if ($error_no == 0) {
        	echo "cURL uploaded the file succesfully.";
        } else {
        	die ("cURL had an upload error, error #".$error_no.$error_msg."Response=".$response);
        }
	fclose($fp);

Comments / discussions

Olaf posted on 2009-05-31 07:14:36 #

Hi,
you have a limit for uploads and you're able to change the php.ini? That make no sense...

There is only one type of ftp transfer, If you're able to upload 50-100mb via a regular ftp client you should be able to do the same via curl (if you're able to upload the file via the browser).

Check this upload tutorial, I use there similar code to backup much bigger files.

Remember uploads via the browser is one, copying files from server to server is another one (you don't send files directly from a browser)