note 24709 added to function.curl-setopt

From: Date: Mon, 26 Aug 2002 18:31:49 +0000
Subject: note 24709 added to function.curl-setopt
Groups: php.notes 
Request: Send a blank email to php-notes+get-35674@lists.php.net to get a copy of this message
To make a POST in multipart/form-data mode this worked for me, the " \n" at the end of the variables was very important on my OS X server. <?php $file = "file_to_upload.txt"; $submit_url = "http://www.url_to_upload_to.com/upload_page.php"; $formvars = array("cc"=>"us \n"); $formvars[variable_1] = "bla bla \n"; $formvars[variable_2] = "bla bla \n"; $formvars[variable_3] = "bla bla \n"; $formvars[variable_4] = "bla bla \n"; $formvars[upfile] = "@$file"; // "@" causes cURL to send as file and not string (I believe) // init curl handle $ch = curl_init($submit_url); curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt"); //initiates cookie file if needed curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt"); // Uses cookies from previous session if exist curl_setopt($ch, CURLOPT_REFERER, "http://www.last_url_for_referer_logs.com"); //if server needs to think this post came from elsewhere curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); // follow redirects recursively curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $formvars); // perform post echo $pnp_result_page = curl_exec($ch); curl_close ($ch); ?> -- http://www.php.net/manual/en/function.curl-setopt.php http://master.php.net/manage/user-notes.php?action=edit+24709 http://master.php.net/manage/user-notes.php?action=delete+24709 http://master.php.net/manage/user-notes.php?action=reject+24709

« previous php.notes (#35674) next »