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?
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
@Sinnbeck ok I will share the code ,the images is been stored in storage director
@ene Where? What is the exact path to the files? And what is the url you are trying to call them on?
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);
}
@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?
@Sinnbeck yes i could
@ene.. Ok.. Good luck
what does this do
$path = $this->photo->hashName('public/gallery');
@Snapey location where the image is supposed to be stored
@ene OK, good luck
Why exactly did you post this question?
@Snapey on shared hosting the image Uploading isn't working
@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.
@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
@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 exactly
@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)?
@Sinnbeck yes I always use protected guarded in my model so I won't miss any column
@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.