Jump to content

Recommended Posts

Posted

I'm trying to create a book database using Amazon AWS API. The problem is I cannot save covers images.

PW returns

Exception: Item added to Pageimages is not an allowed type (in /home/librolo/public_html/wire/core/Array.php line 145) #0 /home/librolo/public_html/wire/core/Pagefiles.php(141): WireArray->add(Object(SimpleXMLElement)) #1 /home/librolo/public_html/wire/core/Pageimages.php(39): Pagefiles->add(Object(SimpleXMLElement)) #2 /home/librolo/public_html/site/templates/grab.php(101): Pageimages->add(Object(SimpleXMLElement)) #3 /home/librolo/public_html/wire/core/TemplateFile.php(88): require('/home/librolo/p...') #4 [internal function]: TemplateFile->___render() #5 /home/librolo/public_html/wire/core/Wire.php(267): call_user_func_array(Array, Array) #6 /home/librolo/public_html/wire/core/Wire.php(229): Wire->runHooks('render', Array) #7 /home/librolo/public_html/wire/modules/PageRender.module(194): Wire->__call('render', Array) #8 /home/librolo/public_html/wire/modules/PageRender.module(194): TemplateFile->render() #9 [internal function]: PageRender->___renderPage(Object(HookEvent)) #10 /home/librolo/public_html/wir in /home/librolo/public_html/index.php on line 202
This error message was shown because the site is in DEBUG mode.

image example

http://ecx.images-amazon.com/images/I/316stS044TL.jpg

Posted

could it be that jpg isn't entered in the image field setting?

are you importing them from external website or url?

Posted

don't know really. does your php setting allow allow_url_fopen? or is save mode on? in case this kind of import from external url wouldn't work.

Posted

and save mode?

or can you provide more details and code what you're trying to do?

or could it be that some images are JPG JPEG ? or something like this?

Posted

I run several pw website on this server so php config is right.

My code is very simple...

include('./amazon.class.php');
// make the request
$keyw = $input->post->keywords;
$xml = simplexml_load_file(awsRequest("Books", "{$keyw}", "Large", "ItemSearch", "1"));
foreach($xml->Items->Item as $item){
      $string = preg_replace("/\[[^\]]*\]/m","",$item->ItemAttributes->Title);
$string = str_replace(".","",$string);
$titolo = strtolower($sanitizer->text(trim($string = preg_replace("/\([^\)]+\)/","",$string))));
$categ=$sanitizer->text($item->BrowseNodes->BrowseNode[0]->Ancestors->BrowseNode->Name);
$subcateg=$sanitizer->text($item->BrowseNodes->BrowseNode[0]->Name);
$publisher=$item->ItemAttributes->Publisher;
$isbn13=$item->ItemAttributes->EAN;
$isbn10=$item->ItemAttributes->ISBN;
$cover=$item->LargeImage->URL;

        $libro = new Page();
$libro->template =  $templates->get("libro");
$libro->parent = $pages->get(1205);
$libro->title = $titolo;
$libro->name = $libro->title;
$libro->autore = $sanitizer->textarea($lineautori);
$libro->save();
$libro->cover->add($cover); 
$libro->save(); 
}
Posted

ah so you got a multiple images field and adding a single one? try to make it an array:

$cover= array($item->LargeImage->URL);
Posted

I think the problem is this line:

$cover=$item->LargeImage->URL;

For instance, try this, and I'm guessing it'll tell you it's an object:

var_dump($item->LargeImage->URL);

When accessing elements like this, SimpleXML returns objects, not strings. You have to typecast it to a string, like this:

$cover = (string) $item->LargeImage->URL;

Many of the other elements you are pulling are already being typecast as strings by way of str_replace, preg_replace, strtolower, $sanitizer->text(), etc., so that's good. But you'll want to typecast these ones as strings too:

$publisher=$item->ItemAttributes->Publisher;
$isbn13=$item->ItemAttributes->EAN;
$isbn10=$item->ItemAttributes->ISBN;
$cover=$item->LargeImage->URL;

This is one of those things about PHP's SimpleXML that has stung me more than once. :)

  • Like 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...