Re: can't figure out proper format for c:\ path for curl upload

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

on 01/05/2008 02:18 AM John Gunther said the following:
> I can't figure out how to pass a c:\... filepath via curl for an RFC1867
>  multipart form upload in PHP 5.2.1.
> 
> I'm using the following code to perform a programmatic file upload to
> the PHP server:
> 
> $filepath='/home/user/testfile.txt';
> $ch=curl_init('http://bucksvsbytes.com/upload.php');
> curl_setopt($ch,CURLOPT_POST,true);
> curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
> curl_setopt($ch,CURLOPT_POSTFIELDS,array('peru'=>'@'.$filepath));
> curl_exec($ch);
> curl_close($ch);
> 
> Works great if the file I want to upload is on the web server but it
> never is. The files I want are on the client computer, of course, e.g.
> c:\home\user\testfile.txt
> 
> I've tried passing every variation of that path I can think of, e.g.:
> 
> C:\home\user\testfile.txt
> C:\\home\\user\\testfile.txt
> C:/home/user/testfile.txt
> urlencode(...)
> utf8_encode(...)
> 
> and nothing works. I either get the dreaded "failed creating formpost
> data" or the filepath shows up in $_POST and $_FILES is empty. The
> listed formats don't work with fopen() either.
> 
> I've searched dozens of web examples but I can't get it. Help!
> 
> For that matter, is there a better approach than curl for programmed
> uploads of client computer files to the PHP server?

When I use Curl I prefer composing a RAW HTTP request because I am sure
it will work as intended. Whenever possible I prefer using fsockopen
connections. In any case I use this HTTP client request class that wraps
everything and supports form submission with file upload as you need:

http://www.phpclasses.org/httpclient


-- 

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux