Announcement

#1 2016-11-03 20:52:59

jokerboy
Member
2013-09-16
5

[resolved] pwg.images.addSimple issue

Hello,

I moved my Piwigo site. I have everything working fine with the exception of an upload script (php) I use.

I've been using this script for years to upload images automatically to Piwigo but it hasn't worked since moving the site.

I'm using PHP and the pwg.images.addSimple method to upload the images after saving them from an email.

The post to pwg.session.login works successfully, but a post to pwg.images.addSimple returns the following:

<rsp stat="fail">
        <err code="405" msg="The image (file) is missing" />
</rsp>

The image file being used is where it should be as I do other operations on the file.

Uploads from the Piwigo built-in administrator area are working fine.

Things that changed when I moved the site are: PHP from 5 to 7.  Ubuntu 14.04 to 16.04.

Any help or clues are greatly appreciated.  Thanks!

Piwigo version: 2.8.2
PHP version: 7
MySQL version: 5.7.16

Offline

 

#2 2016-11-03 21:23:25

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

Re: [resolved] pwg.images.addSimple issue

Hi jokerboy,

In file include/ws_functions/pwg.images.php you can read :

Code:

function ws_images_addSimple($params, $service)
{
  global $conf;

  if (!isset($_FILES['image']))
  {
    return new PwgError(405, 'The image (file) is missing');
  }

It means at this stage of the code execution, PHP does not find the posted image file. My experience tells me you should first check your php.ini file:

* upload_max_filesize (must be bigger than the filesize of the image you want to upload)
* post_max_size (must be bigger than upload_max_filesize)

Offline

 

#3 2016-11-03 21:25:23

jokerboy
Member
2013-09-16
5

Re: [resolved] pwg.images.addSimple issue

Figured it out myself so I'll post the answer here.

I've no experience in php, but apparently some of the syntax I was using has been deprecated which was causing the error.

When I specified the 'image' parameter I was using:

$data2 = array(
        'method' => 'pwg.images.addSimple',
        'image' => "@".$filename,
        'category' => '5',
        'name' => ' my photo caption ',
        'author' => 'Sir Author'
        );

There is now a better way to handle files apparently.  Here's the way that now works (with PHP 7).

$data2 = array(
        'method' => 'pwg.images.addSimple',
        'image' => new CurlFile($filename),
        'category' => '5',
        'name' => ' my photo caption ',
        'author' => 'Sir Author'
        );

Offline

 

#4 2016-11-03 21:36:38

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

Re: [resolved] pwg.images.addSimple issue

OK, so I was completely wrong :-)

Thank you very much for your code sample, working on PHP 7 !

Offline

 

#5 2019-03-03 18:16:43

atkinja
Member
2019-03-03
2

Re: [resolved] pwg.images.addSimple issue

Ironically I am still getting the same problem, even when using the recommendations on SIZE and the new CurlFile.


<?php⏎
include('Requests/library/Requests.php');⏎
Requests::register_autoloader();⏎
$user = "my-user";⏎
$password = "my-password";⏎
$url = "my-url";⏎
$session = new Requests_Session($url);⏎
$body = array(⏎
␉·······'method' => 'pwg.session.login',⏎
␉·······'username' => $user,⏎
␉·······'password' => $password⏎
);⏎
$response = $session->post($url,array() ,$body );⏎
$params = array(⏎
␉·······'method' => 'pwg.session.getStatus'⏎
);⏎
$s = $session->post($url,array() ,$params );⏎
$manage = json_decode($s->body, true);⏎
$token =  $manage['result']['pwg_token'];⏎
$filepath = "test.jpg";⏎
$filename = "sloth";⏎
$settings = array(⏎
␉·······'method' => 'pwg.images.addSimple',⏎
␉·······'category'=>'1',⏎
␉·······'pwg_token'=> $token,⏎
␉·······'image'=> new CurlFile($filepath),⏎
␉·······'name' => $filename⏎
␉·······);⏎
print_r($settings);⏎
$t = $session->post($url,array( 'Content_Type' => 'form-data') , $settings );⏎
print ($t->body);⏎



That code still shows: {"stat":"fail","err":405,"message":"The image (file) is missing"

PHP 7.1.23
Latest version of piwigo as I just downloaded it

This seems so basic to do, yet I am failing to get it o upload the image. 

Any thoughts?  And preferably I don't want the image to be a local file, but rather a URL I reference on the web.

Offline

 

Board footer

Powered by FluxBB

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