Hide copy warnings in PHP

I know that it is not recommended to hide warnings with @copy, but what other alternatives exist?

Is there a way to make sure the copy will work or not?

+4
source share
3 answers

Use is_readable () and is_writable () to check the source and target status before trying to copy ().

+6
source

Indeed, you should not display errors in the browser. Turn off display_errors in php.ini.

You can then check to see if its logical return value succeeded without worrying about the warnings on the screen.

 if (!copy('srcfile', 'destfile')) { // something failed. } 
+1
source

If you use the "@" in front of the function, you will not receive a warning or notification, but you will save the result (boolean, string ...).

Try the following:

 if ( !@copy ('srcfile', 'destfile')) { // something failed. } 
+1
source

Source: https://habr.com/ru/post/1390867/


All Articles