Rectangle 27 29

The trick is to name the file uploading parameters unique.

curl -F "image=@file1.gif" -F "image2=@file2.gif"  http://localhost:8888/web/Upload.php
$_FILES
$_FILES['image']
$_FILES['image2']

To make the files grouped under one $_FILES index you need to name the parameters as arrays:

curl -F "image[]=@file1.gif" -F "image[]=@file2.gif"  http://localhost:8888/web/Upload.php

Actually I'd seen the following page php.net/manual/en/features.file-upload.multiple.php which showed you could upload as an array pictures[]["error"]. i was wondering if that was possible from curl

this is just for testing a web service which will be used by an iphone app. it will load a numer of images at once

Oh, that can be achieved witch curl if you name the params as arrays. Updated example.

upload multiple files to php server using curl command line - Stack Ov...

php curl
Rectangle 27 1

1- your upload form or function is on the server that receives the fil...

Hello I know the ticket was open a while ago but i have been looking for this complete code for a while and I only found pieces of it on the net but nothing that fully worked, so here it is. I hope it helps some people.

I saw your post and i had exactly the same issue using most of the information found here - main author of the code below with w3schools.

Here is how it can be done, two ways :

// the index.php file on the server
<br><br>
<?php /* includes */ require_once 'upload.php'; ?>

<!DOCTYPE html>
<html><body> Formulaire de tlchargement d'une image <br><br>

<form action="upload.php" method="POST" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>
</body> </html>

the upload.php file, in the same dir in this case

<?php
// writing in a sublfolder called image 
$target_dir = "image/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {

    // give a name and direction to the image - i changed the name to test.jpg...
    $uploadfile = $_SERVER['DOCUMENT_ROOT'].$target_dir.'test.jpg';
    echo "<br><br>";
    echo $uploadfile;
         echo "<br><br>";

    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $uploadfile)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}

?>

Server that sends the file (your web server) : send.php

<?php
    // I uploaded a file called sample2.jpeg from on server to another
    // again you can make functions out of this
    $target_url = 'http://192.168.56.103/receive.php';
        //This needs to be the full path to the file you want to send.


$file_name_with_full_path = realpath('./sample2.jpeg');
            /* curl will accept an array here too.
             * Many examples I found showed a url-encoded string instead.
             * Take note that the 'key' in the array will be the key that shows up in the
             * $_FILES array of the accept script
             */
        //$post = array('extra_info' => '123456','file_contents'=>'@'.$file_name_with_full_path);
        $post = array('file_contents' => new CurlFile($file_name_with_full_path, 'text/plain' /* MIME-Type */,'' /*directory*/));

            $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$target_url);
        curl_setopt($ch, CURLOPT_POST,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        $result=curl_exec ($ch);
        curl_close ($ch);
        echo $result;
    ?>

and the file on the receiving server end : receive.php

<?php
// you can chage the destination path
$uploaddir = realpath('./') . '/';
$uploadfile = $uploaddir . basename($_FILES['file_contents']['name']);

echo "<br><br>";
print_r ($uploadfile);
echo "<br><br>";

echo '<pre>';
        if (move_uploaded_file($_FILES['file_contents']['tmp_name'], $uploadfile)) {
            echo "File is valid, and was successfully uploaded.\n";
        } else {
            echo "Possible file upload attack!\n";
        }
        echo 'Here is some more debugging info:';
        print_r($_FILES);
        echo "\n<hr />\n";
        print_r($_POST);
print "</pr" . "e>\n";
?>



<br><br>Sources and references to other codes : 
<br>http://stackoverflow.com/questions/12667797/using-curl-to-upload-post-data-with-files
<br>http://stackoverflow.com/questions/15200632/how-to-upload-file-using-curl-with-php
<br>http://code.stephenmorley.org/php/sending-files-using-curl/
<br>http://www.w3schools.com/php/php_file_upload.asp

Thanks again to the true authors of 99% of the code, fixed with peoples comment on stackoverflow forum : derakkilgo and W3SCHOOLS.

php - Getting error with move_uploaded_file HTTP wrapper does not supp...

php
Rectangle 27 1

1- your upload form or function is on the server that receives the fil...

Hello I know the ticket was open a while ago but i have been looking for this complete code for a while and I only found pieces of it on the net but nothing that fully worked, so here it is. I hope it helps some people.

I saw your post and i had exactly the same issue using most of the information found here - main author of the code below with w3schools.

Here is how it can be done, two ways :

// the index.php file on the server
<br><br>
<?php /* includes */ require_once 'upload.php'; ?>

<!DOCTYPE html>
<html><body> Formulaire de tlchargement d'une image <br><br>

<form action="upload.php" method="POST" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>
</body> </html>

the upload.php file, in the same dir in this case

<?php
// writing in a sublfolder called image 
$target_dir = "image/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {

    // give a name and direction to the image - i changed the name to test.jpg...
    $uploadfile = $_SERVER['DOCUMENT_ROOT'].$target_dir.'test.jpg';
    echo "<br><br>";
    echo $uploadfile;
         echo "<br><br>";

    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $uploadfile)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}

?>

Server that sends the file (your web server) : send.php

<?php
    // I uploaded a file called sample2.jpeg from on server to another
    // again you can make functions out of this
    $target_url = 'http://192.168.56.103/receive.php';
        //This needs to be the full path to the file you want to send.


$file_name_with_full_path = realpath('./sample2.jpeg');
            /* curl will accept an array here too.
             * Many examples I found showed a url-encoded string instead.
             * Take note that the 'key' in the array will be the key that shows up in the
             * $_FILES array of the accept script
             */
        //$post = array('extra_info' => '123456','file_contents'=>'@'.$file_name_with_full_path);
        $post = array('file_contents' => new CurlFile($file_name_with_full_path, 'text/plain' /* MIME-Type */,'' /*directory*/));

            $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$target_url);
        curl_setopt($ch, CURLOPT_POST,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        $result=curl_exec ($ch);
        curl_close ($ch);
        echo $result;
    ?>

and the file on the receiving server end : receive.php

<?php
// you can chage the destination path
$uploaddir = realpath('./') . '/';
$uploadfile = $uploaddir . basename($_FILES['file_contents']['name']);

echo "<br><br>";
print_r ($uploadfile);
echo "<br><br>";

echo '<pre>';
        if (move_uploaded_file($_FILES['file_contents']['tmp_name'], $uploadfile)) {
            echo "File is valid, and was successfully uploaded.\n";
        } else {
            echo "Possible file upload attack!\n";
        }
        echo 'Here is some more debugging info:';
        print_r($_FILES);
        echo "\n<hr />\n";
        print_r($_POST);
print "</pr" . "e>\n";
?>



<br><br>Sources and references to other codes : 
<br>http://stackoverflow.com/questions/12667797/using-curl-to-upload-post-data-with-files
<br>http://stackoverflow.com/questions/15200632/how-to-upload-file-using-curl-with-php
<br>http://code.stephenmorley.org/php/sending-files-using-curl/
<br>http://www.w3schools.com/php/php_file_upload.asp

Thanks again to the true authors of 99% of the code, fixed with peoples comment on stackoverflow forum : derakkilgo and W3SCHOOLS.

php - Getting error with move_uploaded_file HTTP wrapper does not supp...

php
Rectangle 27 0

echo '<pre>';
var_dump(curl_version());
echo '</pre>';
array(9) {
  ["version_number"]=>
  int(463621)
  ["age"]=>
  int(3)
  ["features"]=>
  int(1565)
  ["ssl_version_number"]=>
  int(0)
  ["version"]=>
  string(6) "7.19.5"
  ["host"]=>
  string(24) "x86_64-unknown-linux-gnu"
  ["ssl_version"]=>
  string(14) "OpenSSL/0.9.8b"
  ["libz_version"]=>
  string(5) "1.2.3"
  ["protocols"]=>
  array(8) {
    [0]=>
    string(4) "tftp"
    [1]=>
    string(3) "ftp"
    [2]=>
    string(6) "telnet"
    [3]=>
    string(4) "dict"
    [4]=>
    string(4) "http"
    [5]=>
    string(4) "file"
    [6]=>
    string(5) "https"
    [7]=>
    string(4) "ftps"
  }
}

that means it is enabled, make sure that other settings match such as short tags, etc on both servers.

i am getting an error from the target server which looks like its getting a corrupted file.

php - cURL file upload problem in hosted server - Stack Overflow

php curl
Rectangle 27 0

Curl just need the full path of the file that you wanted to upload with '@' before it.

if (isset($_FILES['uploadedfile']) ) {
    $filePath  = $_FILES['uploadedfile']['tmp_name'];

    $POST_DATA = array(
        'file' => '@'.  realpath($filePath)
    );

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, 'http://extserver.com/handle.php');
    curl_setopt($curl, CURLOPT_TIMEOUT, 30);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $POST_DATA);
    $response = curl_exec($curl);
    curl_close ($curl

     if($errno = curl_errno($curl)) {
        $error_message = curl_strerror($errno);
        echo "cURL error ({$errno}):\n {$error_message}";
    } else {
        echo "<h2>File Uploaded</h2>";
    }
}

Prefer using <?php instead of <?

If you want to check if there is any error with curl use this

if($errno = curl_errno($curl)) {
    $error_message = curl_strerror($errno);
    echo "cURL error ({$errno}):\n {$error_message}";
}

I haven't tried this code yet but i will select it as an answer as it looks good and seems to do what I am trying to do. thumbs up.

I did try your code as is with the error reporting and it didn't work! it only uploads a file called subins onto the remote server with no extensions and 0 BYETS of data in it which means its empty! any idea?

@shell Try with the new code that I edited

php - Upload zip file onto remote server using CURL? - Stack Overflow

php
Rectangle 27 0

Is it not possible to cache the file on your server and then delete it after upload? I wrote a Flickr -> Facebook Photo Album app that does this very thing.

All right, well if you don't want to do that, you can do this:

Edit the file facebookapi_php5_restlib.php, tracing the photo upload calls down to the actual curl call, which is in:

Now the hacky part, instead of passing the filename for $file, pass in an array and then check if its an array in this function. If it is, extract the binary data from it and set it as one of the post parameters. Some curl parameters that you may need can be found here:

Possible, but I'm really trying to avoid it. Seems messy to download, save, upload, delete.

curl - Upload file from remote server... (PHP) - Stack Overflow

php curl
Rectangle 27 0

Yes, make sure that curl extension is enabled where you want to use it. You can check it with:

echo '<pre>';
var_dump(curl_version());
echo '</pre>';

if there was an error, then it means that you do not have this extension enabled. and you will see an error similar to this one:

Fatal error: Call to undefined function curl_version() in testcurl.php on line 2
extension=php_curl.dll

php - cURL file upload problem in hosted server - Stack Overflow

php curl
Rectangle 27 0

If you are using Windows, your file path separator will be \ not the Linux style /.

If you want to make your script portable so it will work on with Windows or Linux, you can use PHP's predefined constant DIRECTORY_SEPARATOR

$post=array('image'=>'@'.getcwd().'images' . DIRECTORY_SEPARATOR .'image.jpg');

php - cURL upload files to remote server on MS Windows - Stack Overflo...

php windows linux curl upload
Rectangle 27 0

if working with xampp Make sure that in php.ini configuration file

Line number 952 is uncommented i.e if line is

;extension=php_curl.dll
extension=php_curl.dll

The curl is working but there was the error the different error.

php - cURL upload files to remote server on MS Windows - Stack Overflo...

php windows linux curl upload
Rectangle 27 0

I think, a better approach would be:

$imgpath = implode(DIRECTORY_SEPARATOR, array(getcwd(), 'images', 'image.jpg'));
$post = array('image'=>'@'.$imgpath);

php - cURL upload files to remote server on MS Windows - Stack Overflo...

php windows linux curl upload
Rectangle 27 0

Get the file name through text box and in background use php curl function to upload the file in the server and your uploading class will work fine PHP Curl to upload file

PHP image upload and crop with url - Stack Overflow

php image-processing image-uploading
Rectangle 27 0

Yes it is possible using pure PHP fopen together with stream_context_create. The following example comes from the online PHP manual (http://php.net/manual/en/function.stream-context-create.php):

function do_post_request($url, $postdata, $files = null) 
{ 
    $data = ""; 
    $boundary = "---------------------".substr(md5(rand(0,32000)), 0, 10); 

    //Collect Postdata 
    foreach($postdata as $key => $val) 
    { 
        $data .= "--$boundary\n"; 
        $data .= "Content-Disposition: form-data; name=\"".$key."\"\n\n".$val."\n"; 
    } 

    $data .= "--$boundary\n"; 

    //Collect Filedata 
    foreach($files as $key => $file) 
    { 
        $fileContents = file_get_contents($file['tmp_name']); 

        $data .= "Content-Disposition: form-data; name=\"{$key}\"; filename=\"{$file['name']}\"\n"; 
        $data .= "Content-Type: image/jpeg\n"; 
        $data .= "Content-Transfer-Encoding: binary\n\n"; 
        $data .= $fileContents."\n"; 
        $data .= "--$boundary--\n"; 
    } 

    $params = array('http' => array( 
           'method' => 'POST', 
           'header' => 'Content-Type: multipart/form-data; boundary='.$boundary, 
           'content' => $data 
        )); 

   $ctx = stream_context_create($params); 
   $fp = fopen($url, 'rb', false, $ctx); 

   if (!$fp) { 
      throw new Exception("Problem with $url, $php_errormsg"); 
   } 

   $response = @stream_get_contents($fp); 
   if ($response === false) { 
      throw new Exception("Problem reading data from $url, $php_errormsg"); 
   } 
   return $response; 
} 

//set data (in this example from post) 

//sample data 
$postdata = array( 
    'name' => $_POST['name'], 
    'age' => $_POST['age'], 
    'sex' => $_POST['sex'] 
); 

//sample image 
$files['image'] = $_FILES['image']; 

do_post_request("http://example.com", $postdata, $files);

PHP - Upload file to another server without curl - Stack Overflow

php file-upload curl
Rectangle 27 0

Try changing the user agent to see if that makes a difference. For example:

curl --user-agent "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.68 Safari/534.24"

php - When upload file: Curl return "Empty reply from server" only on ...

php curl
Rectangle 27 0

  • Rename the tmp file. It is accessible to you, so renaming it is trivial: rename(oldname, newname)
  • Send a mimetype. The format is: @filename;type=image/png for a png.

Prefer the first option if you care about the filename, option two if you only care about the mime type.

PHP: Send uploaded file with curl without uploading to initial server ...

php file-upload curl
Rectangle 27 0

We had the exact same issue for one of my client's projects. We looked at it a couple of different ways, and decided that the best thing to do was to pass the URL to our own server and handle the upload there. In our specific instance, we used cURL with PHP/Codeignitor, grabbed the file, and then uploaded it to S3 (but the same could easily be done for a Parse upload).

We looked at using CloudCode with a httpRequest, but the problem there is the execution timeout. Parse only gives a short time to each CloudCode function, and the file never would've finished downloading before we got timed-out.

In the sense that what if 10 PDF document URL were being sent to parse simultaneously, would I have a chance of experiencing a timeout? I have notice that Parse has recently added a new class for file Parse.file, have you had any experience with that - parse.com/docs/js_guide#files-classes?

I am not sure I understand your question regarding 10 PDF documents being sent at once. You upload 10 Parse.Objects simultaneously, so saving 10 URLs at the same time wouldn't be an issue. As for Parse.File, it has been around for quite some time, but you need to send it a Base64 string representation of the data...which means you need to download the PDF from the URL first and convert it. You really need to do this server-side.

parse.com - Upload file to Parse (Javascript) - Stack Overflow

javascript parse.com google-drive-sdk
Rectangle 27 0

Make sure file uploads are enabled on the server side, and initialize the SDK with fileUpload set to true as described on the PHP SDK documentation page, or call setFileUploadSupport. You don't need to manually call the graph API with the access token and curl commands as you are doing above, the PHP SDK will take care of that for you. See the api method documentation page for a complete example.

php - How to use the graph API to upload photos to albums - Stack Over...

php facebook-graph-api
Rectangle 27 0

Theoretically, your code should not work(i mean upload) in any, unix or windows. Consider this portion from your code:

'image'=>'@'.getcwd().'images/image.jpg'
getcwd()
F:\Work\temp
/root/work/temp
'image'=>'@F:\Work\tempimages/image.jpg'
'image'=>'@/root/work/tempimages/image.jpg'

Since you mentioned it worked for you in linux, which means /root/work/tempimages/image.jpg somehow existed in your filesystem.

My PHP version: Linux: PHP 5.1.6 Windows: PHP 5.3.2

php - cURL upload files to remote server on MS Windows - Stack Overflo...

php windows linux curl upload
Rectangle 27 0

echo $post['image'];

Does it print out the correct file path? Are you running this as CLI or an Apache installation on Windows? You might have to use:

$post['image'] = '@'.dirname(__FILE__).'\\images\\image.jpg';

php - error when upload file to remote server (Windows, cURL) - Stack ...

php windows file curl upload
Rectangle 27 0

So for diagnosing SSH / SFTP problems I think phpseclib, a pure PHP SFTP implementation, is the best approach. Here's how:

<?php
include('Net/SFTP.php');

define('NET_SFTP_LOGGING', NET_SFTP_LOG_COMPLEX);

$sftp = new Net_SFTP('www.domain.tld');
if (!$sftp->login('username', 'password')) {
    exit('Login Failed');
}

$sftp->put('text.txt', 'text.txt', NET_SFTP_LOCAL_FILE);

echo $sftp->getSFTPLog();
?>

In particular, what's useful about phpseclib is it's ability to create log files so you can see what's going on.

php - How to upload file with curl on sftp server - Stack Overflow

php curl