1

I have more than 8000 images in my laravel project and most of these images are in different type distentions. So what I trying to do is check and dimensions of images via getimagesize() but when i use this function in laravel controller it dosen't output anything . Please refer the code that I have tried. When I dd() the image url its working but when I pass the url to the function it just exceed the execution time and nothing happen. But if I pass a different url to the method (something almost hosted) It output the result I wants. I have gone through below question and Yes I feel that there is something with the path of the image. So could anyone please help me to solve this.

    <?php

namespace App\Http\Controllers;

use App\Product;
use function asset ;
use Illuminate\Http\Request;
use ParagonIE\Sodium\File;

class testingController extends Controller
{
   public function testing (){

       //fetching all the products from the DB
       $products = Product::all();

       //looping the products and generating image path
      foreach ($products as $product) {

        //image path
        $img = asset ( 'uploads/products_thumbnails').'/'.$product->thumbnail_file_name;

      //  dd($img); //this is working

        //http://localhost:8000/products/1234568.jpg

        $check = getimagesize ( $img);

        dd($check); //this dosen't output anything

        // if ( File::exists($img)){

        // }
      }
   }
}

But if I trying something like below its working

  $check = getimagesize ( 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png');

    dd($check); 

   array:6 [▼
  0 => 272
  1 => 92
  2 => 3
  3 => "width="272" height="92""
  "bits" => 8
  "mime" => "image/png"
]

Please note that I have almost gone through below questions.

PHP getimagesize() not working

How i get width and height of a image in Laravel Framework?

Nipun Tharuksha
  • 2,496
  • 4
  • 17
  • 40
  • 3
    Why are you trying to read those images via HTTP in the first place? Assuming the images are “local”, this should happen via the file system … – 04FS Nov 26 '19 at 12:01
  • 2
    Is this not the most informative part of thi question ___exceed the execution time___ – RiggsFolly Nov 26 '19 at 12:03
  • @RiggsFolly you are correct I have increased the time. But no luck – Nipun Tharuksha Nov 26 '19 at 12:05
  • @04FS is there is anyother way – Nipun Tharuksha Nov 26 '19 at 12:05
  • How did you increase the time – RiggsFolly Nov 26 '19 at 12:09
  • @RiggsFolly via putting this in my controller `ini_set('max_execution_time', 180); //3 minutes` with the help of this `https://stackoverflow.com/questions/30270316/how-to-solve-a-timeout-error-in-laravel-5` – Nipun Tharuksha Nov 26 '19 at 12:11
  • I can’t find if Laravel has a dedicated method to get the file system paths to an asset at a quick glance - but I assume based on what you have, `'uploads/products_thumbnails` and `$product->thumbnail_file_name`, you should be able to assemble the correct file system path yourself. – 04FS Nov 26 '19 at 12:15
  • Yes it’s working perfectly it also generate the image url too. But it’s not returning the expected result – Nipun Tharuksha Nov 26 '19 at 12:44

1 Answers1

1

Problem is with this function

$img = asset ( 'uploads/products_thumbnails').'/'.$product->thumbnail_file_name;

Try accessing your public folder without asset function.

$img = 'uploads/products_thumbnails/'.$product->thumbnail_file_name;
Shalin Nipuna
  • 450
  • 7
  • 14