Pathinfo parameter 1 error Laravel

765 Views Asked by At

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!

0

There are 0 best solutions below