Mazzu98's avatar

Error uploading image on laravel 9

I have an api to update user image, this works fine but the response shows this message and ruins all json format

<br />
<b>Notice</b>:  PHP Request Startup: file created in the system's temporary directory in <b>Unknown</b> on line <b>0</b><br />
{
    "status": "200",
    "message": "user updated"
	 ...
}

I checked the "upload_tmp_dir" on php.ini and exists, also i run a chmod 777 just in case.

This is the path of upload_tmp_dir "D:\Program Files\Xampp\tmp" (windows)

I tried adding "error_reporting()" on the index.php but it didn't work

UPDATE: sharing code

$path = Storage::disk('public')->put(env('PROFILE_IMGS'), $file);

Im uploding images like that, the image uploads fine, i have no problem with functionality, my problem is with that response that breaks the json.

0 likes
11 replies
kokoshneta's avatar

See this StackExchange answer. You didn’t share any of your code, so we have no idea what you’re actually doing, but probably you’re not specifying a location where the images should be shared, or the folder you’re specifying doesn’t exist.

Mazzu98's avatar

@kokoshneta Yeah i saw that post, i tried to add the error_reporting(), but i didn't know exactly where to set it. Where should it be?

kokoshneta's avatar

@Mazzu98 Setting error reporting (to false in this case) doesn’t actually change anything, it just suppresses the notice. You should be trying to fix the underlying issue instead.

So based on the code you’ve added in, it would appear that the folder specified in env('PROFILE_IMGS') does not exist. What is the value of env('PROFILE_IMGS'), and does that folder exist in your public disk?

The easiest way to figure out if it exists or not would be to do this (you can do it in Tinker):

dd(Storage::disk('public')->exists(env('PROFILE_IMGS'));
Mazzu98's avatar

@kokoshneta yes, the env variable exist and the file is saving in the correct directory, that's why I don't think the problem is in the code, I think I'm missing some configuration, cause the code is working fine

Mazzu98's avatar

@kokoshneta I just commented all my controller code and the warning still bodering, I realized that it appears when I send a file in the form data body, if I took of the file the warning doesn't appear any more (ALL CODE COMMENTED)

Snapey's avatar

make sure you specify that you require a json response in your post request

oh, never use env() directly in your code as it will break if you cache config

https://youtu.be/AWTUpT7krAs

Mazzu98's avatar

@Snapey Im seting the controller function like this:

public function clientDataUpdate(Request $request): JsonResponse

and the response like this:

return response()->json(['status' => '200', 'message' => 'Usuario actualizado']);

About the env() I don't think thats the problem cause I dd it and it have the value, but thanks for the advice.

Mazzu98's avatar
Mazzu98
OP
Best Answer
Level 1

I just solved it, it was a permission problem with windows, i had xampp installed in D:/, I reinstalled to C:/ and the warning disappeared. Even so,thanks for the help.

Snapey's avatar

@Mazzu98 dont forget to change your code to not use env() helper outside of config files

1 like

Please or to participate in this conversation.