0

Hi all

I found cURL and want to use it to upload a file after a form has been submitted. I found the following code on http://php.net/curl

<?php

/* http://localhost/upload.php:
print_r($_POST);
print_r($_FILES);
*/

$ch = curl_init();

$data = array('name' => 'Foo', 'file' => '@/home/user/test.png');

curl_setopt($ch, CURLOPT_URL, 'http://localhost/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch);
?>

Now I'd just like to know if I would use my usual file upload code on upload.php in order to upload the file or would I need to alter my code to accommodate cURL???

Edited by Venom Rush: n/a

3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by wrivera
0

Ok so it seems I can't get the information from the file input field.

I tried using a file input in a form without multipart but all I get back is the filename and not the path to the file.

Anyone have any suggestions?

0

Is it even possible to get the path to the file without first uploading the file?

0

Hi,
This link will solve your problem.go through this.

Hi eliza

Thank you for the link. I'm sure it will come in handy. But I'm currently stuck at getting the path from the file input without a temp file being uploaded to the server on submission of the form.

Or am I totally off base here? Is cURL not used on the submission of a form? I've never used cURL before so I have no idea where to start.

0

It seems that what I'm trying to achieve is impossible. All I want to do is validate a Captcha before a file is uploaded to the server. But no matter what I try, when I hit the submit button the file is the first thing to be sent to the server o.O

0

try using ajax instead. You can validate your form and capthca before sending of form data. CURL is good for web services but probably not needed for what your trying to do.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.