PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
hi, i'm new around here and i've got a question. this is a snippet of code from a download manager i'm working on for a client. this part of the code handles a file upload. the filename is a randomly generated uid with the appropriate file extension:
the files acutally do get uploaded to the /files/ directory fine; the problem, however, is that the files are 0kb and empty inside; images are broken, text files are empty, html files contain no code, etc. what could the issue or issues be?
move_uploaded_file() is a built in php function; i don't have source code for it. that is all the code that is relevant to the problem. here is part of my form's html:
move_uploaded_file() is a function included in the core php functionality. it copies a file from the temporary upload directory specified in php.ini to a filename you supply:
[php_man]move_uploaded_file[/php_man]
from php manual: bool move_uploaded_file ( string filename, string destination)
This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.
If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.
If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.
This sort of check is especially important if there is any chance that anything done with uploaded files could reveal their contents to the user, or even to other users on the same system.
Note: When safe mode is enabled, PHP checks whether the files or directories you are about to operate on have the same UID (owner) as the script that is being executed.
Note: move_uploaded_file() is not affected by the normal safe mode UID-restrictions. This is not unsafe because move_uploaded_file() only operates on files uploaded via PHP.
Warning
If the destination file already exists, it will be overwritten.
Oh, that's nice - one of PHP's commands I've never used in over four years.
I usually use [php_man]copy[/php_man] and [php_man]unlink[/php_man] to handle file-uploads.
I can't see anything particularly wrong with your code - you obviously have chmod the upload directory "files" to 0755 - otherwise there wouldn't be even empty files in your directory.