4

We imagine that form;

<form action="http://api.blabla.com/huhu.php" method="post" enctype="multipart/form-data">
        <input type="file" name="files[]" />
        <button type="submit">submit</button>
    </form>

I want to upload files to this server without using the form which is above.

I tried this with php curl but I could not.

I want it because I have very large number of files to upload. And this should be automatic with cron jobs.

ecabuk
  • 1,641
  • 1
  • 18
  • 20
  • You can use file_get_contents. See : [http://stackoverflow.com/questions/4003989/upload-a-file-using-file-get-contents][1] [1]: http://stackoverflow.com/questions/4003989/upload-a-file-using-file-get-contents – Macbric Sep 12 '13 at 14:05

1 Answers1

5

This is an example of file uploading with cURL you could start with:

$ch = curl_init('http://api.blabla.com/huhu.php');
curl_setopt_array($ch, array(
    CURLOPT_POSTFIELDS => array(
        'files[]' => '@/path/to/file',
    ),
));
if (false === ($res = curl_exec($ch))) {
    die("Upload failed: " . curl_error($ch));
}

The string '@/path/to/file' has a special meaning because it starts with an @; the string that directly follows it should contain the path of a file you wish to upload.

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309