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

mushood's avatar
Level 41

Image upload not working on server but working on local WAMP server

Hello,

I am having difficulty uploading images on my server but it does work correctly on my local WAMP server.

Here is my controller code:

use Intervention\Image\ImageManagerStatic as Image;
.
.

$image = $request->file('imageUpload');

$filename =  ($image->getClientOriginalName());

$path = public_path('images/' . $filename);

Image::make($image->getRealPath())->save($path);

my $filename is working correctly. If i upload the image manually, the image appears. The images folder has permission 777

I dd(php.info()) and the file_uploads is ON and my image size is 1 MB and upload size limit is 2MB.

Do let me know what I am not doing correctly. Thank you for taking the time to help

-- EDIT: I var_dump the $path and here is what I get: string(65) "/var/www/vhosts/domain.com/domain/public/images/imagename.jpg"

0 likes
7 replies
Chris1904's avatar

upload_max_filesize and post_max_size needs to be greater than 1mb as well. I am sure it is, but might as well get the obvious out of the way.

What's the error that you get?

MaverickChan's avatar

try this

$path ='images/' . $filename;

Image::make($image->save($path);

if (!file_exists($path)) {
            mkdir($path,0777,true);
        }

mushood's avatar
Level 41

@Chris1904 Yes they are both greater i checked my laravel.log file and nothing. No error.

@MaverickChan I tried your code. It runs correctly without this line

Image::make($image->save($path);

But still does not work.

I got this error when i included the line: Method save does not exist.

MaverickChan's avatar

@mushood

sorry my bad it should be :

Image::make($image)->save($path);

i just notice that you don't have to use Image ,because Image is for some editing case , for example , you need to make a thumbnail or rotate the photo.

so , just :

$image->move($path, $filename);

remember , make sure the directory exists . use the code i give you

mushood's avatar
Level 41

@MaverickChan I tried your code. I copy pasted

$image->move($path, $filename);

which is not correct since my path is

$path = public_path('images/' . $filename);

but then in my images folder, the folder "imageName.jpg" got created. But the file itself was not moved. This is due to permission, of course. But this shows that the path is correct. Yet when I correct the path by removing the $filename, code runs well again, but file is still not moved.

mushood's avatar
mushood
OP
Best Answer
Level 41

I finally solved it! The "public" folder on my server is not named "public" but httpdocs.

So I used the following code to get my path:

$path = base_path().'/../httpdocs/images/';

@MaverickChan Any ideas as to why the folder imageName.jpg was created?

MaverickChan's avatar

because Image to handle the saving instead of using move() method.

Please or to participate in this conversation.