1

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.

Kevin Gravell
  • 499
  • 2
  • 7
  • 20
  • 2
    Is it possible that you are using a [debug version of PHP](https://bugs.php.net/bug.php?id=70243)? – Jirka Hrazdil Jan 01 '17 at 20:23
  • @JiriHrazdil How can I check if I am using debug version? And if so, how can i disable it? – Kevin Gravell Jan 01 '17 at 20:28
  • @KevinGravell what does output of `phpinfo()` tell you? Or what does your server tell you? – Martin Jan 01 '17 at 20:29
  • @Martin Yeah, phpinfo() tells me `Debug Build yes `... So, how can I disable it? – Kevin Gravell Jan 01 '17 at 20:32
  • I'm not certain (depends on your exact system) but get in touch with your server admin and get them to install a live version, there are various ways and lots of Q&A about installing PHP, do a google.... – Martin Jan 01 '17 at 20:33
  • @JiriHrazdil, I think a fuller answer built around that bug report would be awesome. If you don't intend to write one, I'll write one later today using that as the main point. – HPierce Jan 01 '17 at 20:46
  • @HPierce I wrote a short answer to my question about it (I haven't much time now to write a fuller answer...), but if you write it I will accept it as right answer – Kevin Gravell Jan 01 '17 at 21:18

3 Answers3

1

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.

Community
  • 1
  • 1
Martin
  • 22,212
  • 11
  • 70
  • 132
  • OP already said they tried `error_reporting(0);` though. I don't see how more finely targeting notices changes anything. – HPierce Jan 01 '17 at 20:43
  • @HPierce The issue itself was caused by a Debug version of PHP being installed, that auto outputs error notices regardless of ini or `error_reporting` settings (as is the nature of debugging). However, the OP was asking the question not to solve the error but to hide the error reporting. My answer shows how the OP can do this while retaining non-notice errors that may be more important. – Martin Jan 01 '17 at 20:45
  • @HPierce I've updated the wording in my answer. Hopefully that clarifies my approach. – Martin Jan 01 '17 at 20:55
  • I'm on `php-5-6-30` both on a dev server and on a preprod server. Both have the debug build on as indicated by the phpinfo output. But only the dev machine shows the message `Notice: No file uploaded in Unknown on line 0`. – Stephane Jun 16 '17 at 08:01
  • The issue lied in the upload directory permissions. Opening the permissions resolved it. – Stephane Jun 16 '17 at 08:07
1

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

Kevin Gravell
  • 499
  • 2
  • 7
  • 20
0

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.

TinaFrieda
  • 171
  • 3
  • 15
  • I would suggest that turning off PHP errors entirely is bad advice. I would ask you reconsider this answer. – Martin Jan 01 '17 at 20:37
  • For production purposes it is acutally quite wise to turn them off, however not for debugging ... that is true. Here it is not an error he is getting but a notice ... in principle nothing serious is going on here. – TinaFrieda Jan 01 '17 at 20:40
  • No, It is not wise to turn off error reports, but it is wise to stop errors outputting to the browser. Error reporting should always be turned on, and on production servers they can be output to an error log file and not the browser. – Martin Jan 01 '17 at 20:42
  • Yes Martin, that is what I meant :) – TinaFrieda Jan 01 '17 at 20:48
  • Tina, what you meant and what you said are not the same thing. `:-p` – Martin Jan 01 '17 at 20:48