Announcement

#1 2012-06-16 14:07:38

Help Me Upload image API
Guest

Help Me Upload image API

Please,help me upload image (pwg.image.addSimple) cURL technology.
Code:

/********************************************************************/
$url = "http://test1.ru/piwigo/ws.php";

$timeout = 5;
if (function_exists('curl_init')) {
        $ch = @curl_init($url);
       
        //@curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        @curl_setopt($ch, CURLOPT_URL, $url);
        @curl_setopt($ch, CURLOPT_HEADER, 1);
        @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
        @curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
        @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
       
        @curl_setopt($ch, CURLOPT_POST, 1);
        @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        @curl_setopt($ch, CURLOPT_POSTFIELDS,
        array('method' => "pwg.session.login",'username'=> "Keys", 'password'=> "778899"
));// 1

/*@curl_setopt($ch1, CURLOPT_POST, 1);
        @curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
        @curl_setopt($ch1, CURLOPT_POSTFIELDS,
        array('method' => "pwg.images.addSimple",
'image' => "test1.ru/Gallery/Cat.jpg",
'category' => "1",
'tags' => "Cat",
'name' => "Cat",
'comment' => "123Cat",
'author' => "John",
'level' => "1"
));*/            // Not Job
       

        $value = @curl_exec($ch);
        $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $status2 = @curl_getinfo($ch);
        //print_r ($status2);
        @curl_close($value);
        if ($value !== false and $status >= 200 and $status < 400)
                $value = substr($value, $header_length);
    }
    print_r ($value);
/****************************************************************/

pwg.session.login prints 1      
pwg.images.addSimple prints Unknown Method or Access Denied.
Please give an example code php. Thanx,Big thanks.

 

#2 2012-06-16 14:31:52

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13789

Re: Help Me Upload image API

I have never coded a multipart/form-data form submission with cURL but I have found this example http://curl.haxx.se/libcurl/php/example … pload.html

Please tell me if it works

Offline

 

#3 2012-06-16 20:49:25

Mr.Keyser
Guest

Re: Help Me Upload image API

oh,please help me, not job

$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_URL,"http://test1.ru/piwigo/ws.php?format.php&method=pwg.session.login");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=KRUZER&password=778899");

ob_start();      // prevent any output
curl_exec ($ch); // execute the curl command
ob_end_clean();  // stop preventing output

curl_close ($ch);
unset($ch);

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=keys&password=778899");
curl_setopt($ch, CURLOPT_URL,"http://test1.ru/piwigo/ws.php?format.php&method=pwg.session.login");

$buf2 = curl_exec ($ch);

curl_close ($ch);

echo "<PRE>".htmlentities($buf2);



  $postdata = array( 'image'=>"Cat.jpg" ,'name' => "blavl");
  $cho = curl_init();
  curl_setopt($cho, CURLOPT_POSTFIELDS, "username=keys&password=778899");
  curl_setopt($cho, CURLOPT_URL, 'http://test1.ru/piwigo/ws.php?format.php&method=pwg.images.addSimple');
  curl_setopt($cho, CURLOPT_RETURNTRANSFER, 0);
  curl_setopt($cho, CURLOPT_POST, 1);
  curl_setopt($cho, CURLOPT_POSTFIELDS, $postdata);
  curl_setopt($cho, CURLOPT_CONNECTTIMEOUT, 30);
  $V = curl_exec($cho);
  curl_close($cho);

pwg.session.login = 1
Access denied

 

#4 2012-06-18 14:08:44

MrKeyser
Member
2012-06-17
1

Re: Help Me Upload image API

Yes plg, its method works. Thanks.

Offline

 

#5 2012-06-23 08:56:03

louiemarques
Member
2012-06-23
1

Re: Help Me Upload image API

thanks for the info...

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact