Is it better to use fwrite() or move_uploaded_file()?
It's more of a coding standards question this one. Which one is, if I can call it "better" to use in file upload handler scripts?
I know that fwrite()
and it's accompanying methods for reading and writing can do it in chunks but using move_开发者_如何学编程uploaded_file()
is much more elegant and shorter code.
Thanks
Use move_uploaded_file()
. It does extra checks to ensure the user is not into any funny business. Also, using fread()
and fwrite()
copies the file, instead of moving it, which is a few orders of magnitude more costly than just moving it (which basically just changes it's name, given that the source and the destination are on the same partition).
You should use fwrite()
for writing to files and move_uploaded_file()
for uploading files.
move_uploaded_file
is preferable. You can read/write files with fwrite
and fread
, but don't forget to check if the file is uploaded by using is_uploaded_file
精彩评论