AwadGorg's avatar

Image upload system works in local host but not in the server

Hello I have this image upload system that works perfect at my localhost but when I upload the project to live serve the image stopped uploading to the storage folder am uploading images to the storage folder and I run the storage link command at live serve here is the code am using

if ($this->photos) {
            Image::where('post_id', $post->id)->delete();
            $counter = 0;
            foreach ($this->photos as $photo) {

                $storedImage = $photo->store('public/photos');

                $featured = false;
                if($counter == 0 ){
                    $featured = true;
                }
                Image::create([
                    'url' => url('storage'. Str::substr($storedImage, 6)),
                    'title' => '-',
                    'post_id' => $post->id,
                    'featured' => $featured
                ]);
                $counter++;
            }
        }
0 likes
4 replies
Sinnbeck's avatar

Any idea where it stops? Is this perhaps false?

if ($this->photos) {

Use dd() to see how far it gets and check the content of your variables

Snapey's avatar

anything in the server logs?

Does the file get added to the server anywhere?

What is this doing?

'url' => url('storage'. Str::substr($storedImage, 6)),

Do you end up with records in the database?

AwadGorg's avatar

@Snapey Does the file get added to the server anywhere? the file gets stored in the storage folder,

What is this doing? this code store the file path in the DB

'url' => url('storage'. Str::substr($storedImage, 6)),

Do you end up with records in the database? yes, it stores in the database.

as I mentioned before the code is working fine at my localhost

Snapey's avatar

@AwadGorg you said both; the file is uploaded and the file is not uploaded.... which is it?

WHY do you substr the file path?

Please or to participate in this conversation.