Jump to content

libcURL FTP script creating empty files


sbaker

Recommended Posts

Hi all.  I work at a university library where I am the default web coding person.  Although I know far more than anyone else who works here, my skills are not exactly at the guru level. 

 

At the moment I'm fighting with libcURL, trying to use a (secured) submission form to upload files from faculty to a remote server.  (Of course, I had one that worked which uploaded to a safe directory on our web server, but that was deemed insufficient.  ::) )

 

I have managed to connect to the FTP server with cURL, and I have managed to create files on that server which have the same name as the files uploaded in the form.  However, for some reason that escapes me, the files created on the FTP server are empty files.  :confused:

 

The server is using Server 2003 and IIS 6, and I am able to successfully upload to it using Filezilla, so I suspect the problem is with my code.

 

I have searched Google for help with this, but all I can get is examples of how to upload which are the same as the one I already have, and how to delete a file using cURL, which is not what I want to do. 

 

The problem does seem to be somewhere in the file transfer process.  die($_Files['syllabus']['size']); gives me the correct file size, and I tried moving the file onto the (local) webserver before transfering it via FTP, and the server one was fine--the FTPed version still showed up empty.

 

If anybody has any idea what's going on, your help would be greatly appreciated.

 

                //the syllabus file from the form
	$syllabus=$_FILES['syllabus']['name'];

                //the syllabus as it will appear on the server (to make it a clickable link in the e-mail sent 
                //to our processing librarian later in the script.  Removing this did not fix the problem anyway.)
	$REMsyllabus = str_replace(' ', '-', $_FILES['syllabus']['name']);

                //formatted URL, with FTP information defined just before the syllabus and REMsyllabus files.
	$SYLremoteurl = "ftp://${ftpuser}:${ftppasswd}@${ftpserver}/${REMsyllabus}";

	$ch = curl_init();

	$fp = fopen($syllabus, 'r');

	curl_setopt($ch, CURLOPT_URL, $SYLremoteurl);
	curl_setopt($ch, CURLOPT_UPLOAD, 1);
	curl_setopt($ch, CURLOPT_INFILE, $fp);
	curl_setopt($ch, CURLOPT_INFILESIZE, $_FILES['syllabus']['size']);
	curl_exec ($ch);
	$error_no = curl_errno($ch);
	curl_close ($ch);
	if ($error_no == 0) {
		$error = 'File uploaded succesfully.';
	} //if
	else {
		$error = 'File upload error: '.$error_no;
	}//else

} //if
else {
$error = 'No syllabus file selected.';
}//else

 

This is pretty much the example code from the libcURL PHP section web page, so I'm not entirely sure why it doesn't work.

 

Thanks in advance for any help anybody can offer!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.