Results 1 to 2 of 2
Thread: PHP upload file using CURL()
Jul 21, 2011, 10:50 #1
PHP upload file using CURL()
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?
$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_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_URL, "http://www.mydomain.com/parse.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "key=YT567BZX9W21DVLK&clientdomain=mydomain.co.uk&cvfile=@".$_FILES['cv']['tmp_name']);
$response = curl_exec($ch);
$errnum = curl_errno($ch);
echo $response; exit;
Jul 24, 2011, 18:38 #2
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.
2. 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.