Php Beginner;10997336 wrote:
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
I'd remove any comments that relates to PHP 4 since it was taken out of production some years ago. I'd also recommend NOT using example that mention PHP 4 since they have to be very very old.
Php Beginner;10997336 wrote:
$uploaddir = '/var/www/uploads/';
It's used to specify the path where uploaded files should be placed (initially they are in a temp directory)
Php Beginner;10997336 wrote:
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
The . operator is used to concatenate strings, and this will take the path and add the filename the file had when being uploaded
Php Beginner;10997336 wrote:
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
You specify the path where the file will be moved to, but do note that it retains the filename it had on the user's computer, which means it is the user that decides what filename to use. Moreover, if you read the documentation for [man]move_uploaded_file[/man], you'll see
Warning
If the destination file already exists, it will be overwritten.
So unless you are actually implementing a system to allow the user to overwrite files, implement warnings etc about this in your system, the user might overwrite a file he didn't mean to. If several users have their files placed in the same directory, they will also be able to overwrite each other's files.
Php Beginner;10997336 wrote:
} else {
echo "Possible file upload attack!\n";
}
Assuming the user did try to do something bad to your system, do you really need to inform him of this? And for any other user, is this a good error message? I'd stick to "File uploaded successfullly" or "There was an error. Please try again". Unless you actually have information about the error which would be useful to the user, such as uploaded file was too big.