mraza Posted March 4, 2010 Share Posted March 4, 2010 hi i am not very well in curl, i have write a function to upload image on a freehost, here is the script: <?php $agent= "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14"; $reffer= "http://www.google.com/"; $cookie_file_path = 'cookie.txt'; $fp = fopen($cookie_file_path,'wb'); if(!$fp) echo 'error opning cookie file'; fclose($fp); $ch = curl_init(); $data = array('content_type' => '1', 'image[]' => '@image.gif'); curl_setopt($ch, CURLOPT_URL, 'http://www.pixhost.org:8080/classic-upload/"'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_REFERER,$reffer); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); $postResult = curl_exec($ch); if (curl_errno($ch)) { print curl_error($ch); } curl_close($ch); print "$postResult"; ?> but its not working, imagehost display an error, that it is close for 10 minutes but i can normaly upload the image, i think they have onsubmit in form that is making problem, here is the code for form <form name="upload" method="post" onsubmit="return image(upload);" enctype="multipart/form-data" action="http://www.pixhost.org:8080/cover-upload/"> <h3>Select pictures: </h3><br /> <div style="padding-bottom:5px;"> <input type="file" name="0" style="margin-top:2px;"/><br /> <input type="file" name="1" style="margin-top:2px;"/> </div> <div style="padding-bottom:5px;"> <input type="file" name="2" style="margin-top:2px;"/><br /> <input type="file" name="3" style="margin-top:2px;"/> </div> <div id="viac"></div> <div style="margin-top:4px;"><a onclick="coverupload();">More</a><br /></div> <div style="padding-top:5px;">Content type: <input type="radio" name="content_type" value="1"/> Adult (XXX) <input type="radio" name="content_type" value="0"/> Family safe </div> <div style="padding-top:5px;">Connect pictures: <input type="checkbox" name="split"/></div> <div style="padding-top:5px;"><h3>I agree with <a href="/tos/">TOS</a> <input type="checkbox" name="tos" checked="checked"/></h3><br /><br />Supported formats: gif, png, jpg.<br />Maximum image size is 5 MB.</div> <div style="padding-top:20px;"><input type="submit" value="Upload"/></div> </form> thanks for any help please Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 4, 2010 Share Posted March 4, 2010 This array is broken for posting $data = array('content_type' => '1', 'image[]' => '@image.gif'); fixed: $data = array('content_type' => '1', 'image' => 'image.gif'); HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
mraza Posted March 4, 2010 Author Share Posted March 4, 2010 Thanks for answer , I tried but it did not make any difference, i left an image named, image.gif in same folder the script is and run the script, its not working even like this Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 4, 2010 Share Posted March 4, 2010 corection: pixhost is img[] HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
mraza Posted March 4, 2010 Author Share Posted March 4, 2010 thanks again i tried $data = array('content_type' => '1', 'image[]' => '@image.gif'); and $data = array('content_type' => '1', 'img[]' => 'image.gif'); and $data = array('content_type' => '1', 'image' => '@image.gif'); and $data = array('content_type' => '1', 'img[]' => '@image.gif'); no luck Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 4, 2010 Share Posted March 4, 2010 I ran it and got their page that said "image upload disabled, down for maintenance". Which they are at the moment. So it works. Must have something to do with your form. Lets have a look at the js. HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
mraza Posted March 4, 2010 Author Share Posted March 4, 2010 No sir, if you try to upload image normally, it will work, not through this script, i am not sure what i am missing.. please try once to upload normally an image it will work , only this script is showing that message. Thanks Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 4, 2010 Share Posted March 4, 2010 OK. I have no idea what the js you are using is, but if it works, OK. Then your form pushes the files off to pixhost. So why do you have the curl code? HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
mraza Posted March 4, 2010 Author Share Posted March 4, 2010 i am trying to upload image through curl to that image site, i do not have any js file except that curl code i show you above, so that script is running stand alone Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 4, 2010 Share Posted March 4, 2010 You are confused about how you must accomplish your task. <form name="upload" method="post" onsubmit="return image(upload);" enctype="multipart/form-data" action="http://www.pixhost.org:8080/cover-upload/"> The onSubmit, says you go to a js function named image(), if the js returns OK you then go to the action which is the upload page at pixhost. Nowhere at any time do you use the curl code you have. You need to remove the onSubmit. You need to change the action to point to your script with the curl code in it. If that is the complete file you showed on your initial post you need to convert your post data then feed it to the curl code. $img=$_POST['img'] You need to change your file inputs in your form to conform to what the data array is...name=img[] You need to change the data array... $img instead of image.gif Do that and your stuff will work. When you have done that, try it. If it does not work come back here and show the complete form and complete curl file. HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
mraza Posted March 4, 2010 Author Share Posted March 4, 2010 the problem is i cant change that image host code means these things i cant do "" You need to remove the onSubmit. You need to change the action to point to your script with the curl code in it. If that is the complete file you showed on "" i m trying to make script to work with that site as that code is, i don't have control on that image site files, html etc Thanks for help Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 4, 2010 Share Posted March 4, 2010 I did not say you had to alter any code on the image host site. I said you had to change the code in the form and curl file you showed in your first post. When I speak of FORM I mean the form code you showed. When I speak of CURL I mean the curl code you showed. Go back to the message where I tell you what to change. Make those changes to the files you showed in your original posting. I know that English is not your first language. I have made myself as clear and concise here as I can. If you cannot understand this message and what I am suggesting you do I can be of no more help. I have just explained it to you the best way I can, if you still dont understand, I'm sorry that I was not able to express myself better, maybe someone else can explain it in a way that will be easier for you to understand. HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
mraza Posted March 4, 2010 Author Share Posted March 4, 2010 sorry for confusion, the form code i display above i don't have that, it was only source code i show from that image host site using to submit images, i need only a php script without any form submission it will run, means as i open the file it will execute as it is doing now, anyway thanks for your time and help i appreciate that. if anyone can help this is only single stand alone file i need to run without any form submission. so when i open this file it will upload an image named "image.gif" to that site. <?php $agent= "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14"; $reffer= "http://www.google.com/"; $cookie_file_path = 'cookie.txt'; $fp = fopen($cookie_file_path,'wb'); if(!$fp) echo 'error opning cookie file'; fclose($fp); $ch = curl_init(); $data = array('content_type' => '1', 'image[]' => '@image.gif'); curl_setopt($ch, CURLOPT_URL, 'http://www.pixhost.org:8080/classic-upload/"'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_REFERER,$reffer); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); $postResult = curl_exec($ch); if (curl_errno($ch)) { print curl_error($ch); } curl_close($ch); print "$postResult"; ?> Thanks Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 4, 2010 Share Posted March 4, 2010 Use the form code, you still need a way to pass image files to your curl file. Do what I told you to do and you will have a working solution. HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
mraza Posted March 7, 2010 Author Share Posted March 7, 2010 Thanks again for your support , ok i tried but it stay the same, here is the code i used, index.html <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”> <html xmlns=”http://www.w3.org/1999/xhtml”> <head> <title>image upload form to pixhost</title> </head> <body> <form method="get" enctype="multipart/form-data" action="curl.php"> <h3>Select picture:</h3> <input type="file" name="img" /><br /> <div>Content type: <input type="radio" name="content_type" value="1"/> Adult <input type="radio" name="content_type" value="0"/> Family safe </div> <div>I agree with TOS<input type="checkbox" name="tos" checked="checked"/></div> <div><input type="submit" value="Upload"/></div> </form> </body> </html> curl.php <?php error_reporting(E_ALL); //echo '<br /><br />' ; //$_GET['img'] = "@image.gif"; //$_GET['content_type'] ="1"; //$_GET['tos'] = "on"; //print_r($_GET); $img = $_GET['img']; $contentType= $_GET['content_type']; $tos = $_GET['tos']; $agent= "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14"; $reffer= "http://www.google.com/"; $cookie_file_path = 'cookie.txt'; $fp = fopen($cookie_file_path,'wb'); if(!$fp) echo 'error opning cookie file'; fclose($fp); $ch = curl_init(); $data = array("content_type" => $contentType , "image" => $img , "tos" => $tos ); curl_setopt($ch, CURLOPT_URL, 'http://www.pixhost.org:8080/classic-upload/"'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_REFERER,$reffer); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); $postResult = curl_exec($ch); if (curl_errno($ch)) { print curl_error($ch); } curl_close($ch); print "$postResult"; ?> and it display again that 10 minutes waiting, thanks for any help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.