Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nero's avatar
Level 1

The result is a picture can not appear in laravel

I've uploaded my project laravel 5 to shared hosting: My laravel project stored in: / Users / nero / laravel.

Folders to upload pictures I put in Users / nero / laravel / public / uploads code to display the image I wrote in router.php.

Here's the code:

    echo asset('/uploads/event/content/'.$finish_file_name);

The result is a picture can not appear. Does the code to display the image there is something wrong?

Can you help me?

0 likes
7 replies
jlrdw's avatar

Is your img src tag working in development server?

nero's avatar
Level 1

If the development server, but when uploaded to the server hosting the picture can not appear

jlrdw's avatar

Does everything else work like editing a record adding a record, etc. Check this because the production server if it's Linux is going to be case sensitive. Verify the files are being stored. Check any log files for errors.

nero's avatar
Level 1

The process of uploading the image file can be. But when that data can not be performed.

Snapey's avatar

Look at the 'view source' in the browser and check the path that is being created.

Show what else you have in your view around the echo statement. How is that echo being used?

If its just an image then why not use blade tags;

    <img src="{{ asset('/uploads/event/content/' . $finish_file_name) }}" />

nero's avatar
Level 1

Snapey: Code to upload and display images I wrote in router.php not view

nero's avatar
Level 1

My Code Can not override image:

    Route::post('ajaximage', function(){
        if(empty($_FILES['file']))
        {
            exit(); 
        }
    else
        {
            /*--------------------Start Pengolahan Gambar---------------*/
            $size      = Input::file('file')->getSize(); // ukuran asli file
            $tmp_name=Input::file('file')->getPathName();
            $image = Input::file('file'); // form input gambar
            //$file = Request::file('file');
            $filename  = time() . '.' . $image->getClientOriginalExtension(); // Ektensi file asli -----pakai
            /*----start buat nama file-----*/
            $date=date('ymd');
            $hours=date('His');
            $kyt='KILO';
            $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789_";
            $acakx = "";
            for($i=0; $i<12; $i++)
            $acakx.=$chars[mt_rand(0,strlen($chars)-1)];
            $name_rand1=$date.$hours.$kyt.$acakx;
            $name_rand2 = rand(1000,100000)."-".$filename;
            $file_name=$name_rand1."content".$name_rand2;
            $finish_file_name = strtolower($file_name);
            /*----end buat nama file-----*/
    
            $dir_name = "uploads/event/content/"; // folder tempat upload file
            $path = public_path($dir_name.$finish_file_name); // lokasi penyimpanan gambar 
            $widthx=450; //lebar gambar
            $sizexx=GetimageSize($tmp_name); //Mengambil ukuran gambar yang asli
            $heightx=round($widthx*$sizexx[1]/$sizexx[0]); // rumus konversi mengecilkan gambar
    
            Image::make($image->getRealPath())->resize($widthx, $heightx)->save($path); // Membuat ulang gambar sesuai  
            dengan ukuran baru
        
            echo url().'/uploads/event/content/'.$finish_file_name;
        }
    });

Please or to participate in this conversation.