I was uploading a file using multipart/form-data, and getting the uploaded file in another php file to use it somewhere else.
This was the multipart/form-data I was using:
<html>
<body>
<form enctype="multipart/form-data" action="facebook.php" method="post">
<p><label for="source">Photo</label><input type="file" name="source" /></p>
<p><input type="submit" value="Upload" /></p>
</form>
</body>
</html>
Now I changed to use cURL to upload the file, because I wanted to upload more the one file, so i needed to not use the form.
This is the code I am using now:
<?php
$ch = curl_init('http://localhost/faceads/facebook.php');
curl_setopt_array($ch, array(
CURLOPT_POSTFIELDS => array(
'files[]' => '@C:\xampp\htdocs\faceads\Assento-Novo.png',
),
));
if (false === ($res = curl_exec($ch))) {
die("Upload failed: " . curl_error($ch));
}
?>
I am trying to get the uploaded file in facebook.php in the same way I was doing before, but it is not working, and because I know almost nothing about cURL I don't know how to do it.
This is the facebook.php file now:
if (!empty($_FILES)) {
$uploaddir = './uploads/'; // Upload folder
$uploadfile = $uploaddir . basename($_FILES['source']['name']);
if (move_uploaded_file($_FILES['source']['tmp_name'], $uploadfile)) {
USE THE FILE URL
.
.
.
}
}
Anyone can help me saying how can I get the uploaded file using cURL?
Thanks