You are here: Re: how to post file with curl « All PHP « IT news, forums, messages
Re: how to post file with curl

Posted by Stefan Rybacki on 08/04/05 13:41

Shailesh Patel wrote:
> hi Stefan,
> thnax for ur reply,i got ur point. but i want to do same
> thing via php curl library not by curl command prompt.
> i searched for curl_setopt options. but bad luck.:( not found.
>
then read again!


"Multipart form uploads (ie simulating the upload of files from a browser form) is
surprisingly easy, yet hard to find information on.... hope this changes that.

$postData = array();

//simulates <input type="file" name="file_name">
$postData[ 'file_name' ] = "@test.txt";
$postData[ 'submit' ] = "UPLOAD";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1 );

//seems no need to tell it enctype='multipart/data' it already knows
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData );

$response = curl_exec( $ch );

//where test.txt is a file in the same directory!"

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация