Upload a file to the server without using a form?

We present the 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 above.

I tried this with php curl but could not.

I want because I have so many files to download. And that should be automatic with cron jobs.

+3
source share
1 answer

This is an example of downloading files using cURL, from which you can start:

$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));
}

A string '@/path/to/file'is of particular importance since it begins with @; the line that immediately follows it should contain the path to the file you want to download.

+5
source

All Articles