0

I got this exception

"[2017-10-13 12:24:56] test.ERROR: ERROR: unable to publish the listing. pathinfo() expects parameter 1 to be string, array given"

this is the xml tag where I get the data

<images>
 <image href="url" comment="Main image" ></image>
 <image href="url" comment="Interior image" ></image>
 <image href="url" comment="Plan image" ></image>
 <image href="url" comment="Main image" ></image>
 <image href="url" comment="Interior image" ></image>
 <image href="url" comment="Plan image" ></image>
</images>

this is how I store data in the database

$images = array();
if(!empty($node->images)) {
    foreach($node->images->image as $image) {
        $images[] = self::parseXMLAttributes($image->attributes());
}

and I serialize it in a field of my database.

'images' => serialize($images),

This is the portion of code that give me the exception:

$images = unserialize($draft->images);
            foreach($images as $i => $image) {
                if ( ($file = @file_get_contents($image)) !== FALSE) {
                    $extension = pathinfo($image, PATHINFO_EXTENSION);
                    $filename = str_slug($draft->title) . "_$i.$extension";

                    //create directory if not exist
                    $directory = public_path() . '/images/uploads/harbours/' . $listing->id;
                    if(!\File::exists($directory)) {
                        \File::makeDirectory($directory, 0775, true);
                    }


                    file_put_contents($directory . '/' . $filename, $file);

                    ListingImage::create(array(
                        'listing_id' => $listing->id,
                        'name' => $filename,
                        'original_name' => $filename,
                    ));
                }
            }

Please answer soon. Thank you!

FranCode
  • 93
  • 1
  • 7
  • I think it should be like this `$extension = pathinfo($image['href'], PATHINFO_EXTENSION);` !! – Maraboc Oct 13 '17 at 11:01
  • Your `$image` contains an array at the moment but you need to put a string value here (`$extension = pathinfo($image, PATHINFO_EXTENSION);`). you can use dd($image) to gather more info of your image. If you cannot resolve this issue on your own with dd($image). Post the information from dd($image) in your question. – Lars Mertens Oct 13 '17 at 11:12
  • No I got, try to get property of non object... How to know in which row? – FranCode Oct 13 '17 at 11:19
  • @FranCode Please check $image value like: print('
    ');
                    print_r($image);
                    print('
    '); exit;
    – AddWeb Solution Pvt Ltd Oct 13 '17 at 11:25
  • I solved the problem. Thanks everyone – FranCode Oct 13 '17 at 16:03

0 Answers0