Notice warning from PHP in Symfony uploading file

1.2k Views Asked by At

I have a form that allows upload three files at the same time but just one is required. That works fine, my only problem is the following: if I upload three files I haven't any problem but if I upload one or two files (leaving two or one files empties) I obtain the following notice:

Notice: No file uploaded in Unknown on line 0

As much as empty files. The files are uploaded properly without any other problem, but I want remove that notice... or unless hide it, although I prefer remove it. I tried to hide it using

error_reporting(0);

and

ini_set('display_errors',0);

but neither of two worked...

It is the first time that I have problem, if someone could lead me I'd be very grateful due to that I am stuck with it.

3

There are 3 best solutions below

0
On BEST ANSWER

If you are having the same problem as me, check with phpinfo() if you are using a debug version of PHP. If you see that Debug Build has a value of yes, your problem will be fixed if you install a live version of PHP instead of a debug version

5
On

Perhaps you may also need to set

 ini_set('error_reporting', 0);

depending on your php ini configuration?

Also make sure you set it before carrying out any of the code.

5
On

The Error itself is caused by running a Debug version of PHP 7, see the bug report. As noted by HPierce because it was a Debug build it overrides the usual PHP settings for error_reporting. However as the Original question is actually about how to hide certain [expected] error messages (Notices), my answer is to this detail specifically.

Kevin, the attempted ways to hide errors you've listed in your question would normally work on non-debug PHP builds. However, it is unwise to ignore the errors, rather than solving them at source. It's also (more) unwise to hide all errors simply due to having expected errors appearing.

As it's only a Notice, you can work around it by setting your error_reporting() value as below:

//report all errors except notices. 
error_reporting(E_ALL & ~E_NOTICE);

I would suggest this is far wiser than turning off error reporting entirely which is not recommended. If you want to stop errors being output to browser (as referenced by Tina) you can use display_errors.