Jump to content

curl onsubmit problem in form


mraza

Recommended Posts

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

 

 

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.