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

ene's avatar
Level 2

issue with image upload after deployment

I just finished deploying my project on a shared hosting services and I noticed that when I try to create a post with image the image isn't been uploaded I don't know why and I'm not getting error and I have link the public directory usually php artisan storage:link

does anyone know how I can solve this issue

0 likes
19 replies
Sinnbeck's avatar

Can we get some code to go by perhaps? Where are you storing it? What driver are you using? Is the file in the storage directory?

ene's avatar
Level 2

@Sinnbeck ok I will share the code ,the images is been stored in storage director

Sinnbeck's avatar

@ene Where? What is the exact path to the files? And what is the url you are trying to call them on?

ene's avatar
Level 2

@Sinnbeck

here is my code

  public function createMovie()
    {
        if (auth()->check()) {
            $this->validate();
            $path = $this->photo->hashName('public/gallery');
            $images = Image::make($this->photo)->fit(840, 840, function ($constraint) {
                $constraint->upsize();
            });
            Storage::put($path, (string)$images->encode());

            $random =  str_pad(mt_rand(1,999999),6,'0',STR_PAD_LEFT);
            $movie = Movie::create([
                'user_id' => auth()->user()->id,
                'title' => $this->title,
                'size' => $this->size,
                'quality' => $this->quality,
                'catalog_id' => $this->catalog,
                'body' => $this->body,
                'movie_number' => $random,
                'url' => $this->url,
                'image' => $path,

            ]);

            session()->flash('success_message', 'Movie was added successfully!');

            $this->reset();

            return redirect()->route('admin.movie');
        }

         abort(Response::HTTP_FORBIDDEN);
    }

Sinnbeck's avatar

@ene still waiting for you to answer the questions

Where? What is the exact path to the files? And what is the url you are trying to call them on?

And as they are actually being stored (you said so above), can you find them in the public directory?

Snapey's avatar

what does this do

$path = $this->photo->hashName('public/gallery');
ene's avatar
Level 2

@Snapey location where the image is supposed to be stored

Snapey's avatar

@ene OK, good luck

Why exactly did you post this question?

ene's avatar
Level 2

@Snapey on shared hosting the image Uploading isn't working

Sinnbeck's avatar

@ene We are asking because it seems that we put more effort into the problem than you. We ask you questions to help us understand the problem, but you answer as if you don't care

location where the image is supposed to be stored

So this works? The image is actually there? Or could that method be broken?

And I asked you what the exact path of the images on the server was, what url you called them on, and if you could find them in the public folder.. Your answer was

yes i could

If you don't want to put any effort into the problem solving, then neither will we.

ene's avatar
Level 2

@Sinnbeck sorry that's was a typo , the images are been stored in the public/gallery folder I also checked the storage/ public/gallery the images where there and I was not getting error when I tried to upload the image. on localhost the image is uploading properly and displaying but on shared hosting the image is not been saved to the database

Sinnbeck's avatar

@ene .. ok so the problem isnt that it isnt uploaded? The image is uploaded and you can open it in a browser? But the path isnt saved in the database.

Is that correct?

Sinnbeck's avatar

@ene Great. So it all boils down to this part

$movie = Movie::create([
                'user_id' => auth()->user()->id,
                'title' => $this->title,
                'size' => $this->size,
                'quality' => $this->quality,
                'catalog_id' => $this->catalog,
                'body' => $this->body,
                'movie_number' => $random,
                'url' => $this->url,
                'image' => $path,

            ]);

Are all columns fillable (or are you using $guarded)?

ene's avatar
Level 2

@Sinnbeck yes I always use protected guarded in my model so I won't miss any column

Sinnbeck's avatar

@ene Ok. Ensure that the code is run. Add a dd() after the that code and see if it triggers

Please or to participate in this conversation.