PHP upload file using CURL()

Hi Guys!

I am trying to upload a file to another server using CURL…Here’s the script that uploads the file from the input server. How do I create the script on the receiving server? For example, I need to move the uploaded file into a folder.

How do I do that?

function UploadCV2(){
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_VERBOSE, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_URL, "");
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, "key=YT567BZX9W21DVLK&".$_FILES['cv']['tmp_name']); 
	$response = curl_exec($ch);
	$errnum = curl_errno($ch);
	echo $response; exit;

Two things come to mind off the top of my head. They could be complete nonsense, but here goes.

  1. Your uploading script on server A could call a script on the other server (B) and use URL vars to trigger the remote script. I’ve never tried this with curl, so I have no idea if it will work.

For instance, your script on server B (the server being uploaded to) could have a line such as: if($_GET[‘uploaded’] == true && file_exists($path_to_file)) which then triggers the script to move the uploaded file.

Or, instead of using curl to trigger the script, you could issue a header redirect after the script has finished uploading, which will then trigger the remote script via a browser, giving it a greater chance of working.

  1. Use a cron job on server B to check the directory every x minutes and move the file if it exists. This one should definitely work since you’re not doing anything remotely.