Better to use fwrite () or move_uploaded_file ()?

This is more in line with coding standards. Which one, if I can call it β€œbetter,” for use in file upload handler scripts?

I know that fwrite() and the associated read and write methods can do this in pieces, but using move_uploaded_file() is a much more elegant and shorter code.

thanks

+4
source share
3 answers

Use move_uploaded_file() . He does additional checks to ensure that the user is not in any funny business. In addition, using fread() and fwrite() copy the file, rather than moving it , is several orders of magnitude more expensive than just moving it (which basically just changes its name , given that the source and destination are in the same section).

+10
source

You must use fwrite() to write to files and move_uploaded_file() to load files.

+3
source

move_uploaded_file is preferred. You can read / write files using fwrite and fread , but be sure to check if the file is is_uploaded_file using is_uploaded_file

+1
source

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


All Articles