You are here: Revise and Repost: Question about Curl and File Uploads « PHP Programming Language « IT news, forums, messages
Revise and Repost: Question about Curl and File Uploads

Posted by HC on 05/15/06 17:35

OK, last time I posted, I must have been totally unclear :) Hopefully
this clears things up:

I wrote the following script that uses Curl to mimic submitting a form
over SSL with <input type='file'>. It works well, but for security
reasons, I would like to not have to write the necessary data to a
temporary file. If anyone could point me in the right direction, that
would be great.

-HC :)


// Write the batch file to a temporary file
$filename = "batchtemp" . time() . ".tmp";
// We will use curl to send this file for processing
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, "https://www.example.com/");
curl_setopt($ch, CURLOPT_POSTFIELDS, array("batchFile"=>"@$filename));
// Write $batchFile to the temporary file.
if (!$file = fopen($filename, "w")) { echo "Cannot open file
($filename)"; exit; }
if (fwrite($file, $batchFile) === FALSE) { echo "Cannot write to file
($filename)"; exit; }
fclose($file);
// Send the data
$txResult = curl_exec($ch);
// We're done with the temp file, and curl.
unlink($filename);
curl_close($ch);

 

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

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