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


/* http://localhost/upload.php:

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


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???

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?

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

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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.