simple file upload

This one is driving e crazy since I have used the same method dozens of times over the years.

Trying to do a simple file upload (will be .pdf and .doc files but for now I have tried all types and nothing works !)
Two scripts

A form to browse and select the file from my pc.


html>

File Upload Form This form allows you to upload a file to the server.

Type (or select) Filename:

and this calls the getfile.php


<?php echo "stage 1"; if ( move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'], "../uploads/{$_FILES['uploadFile'] ['name']}") ) { echo '

The file has been successfully uploaded

'; } else { switch ($_FILES['uploadFile'] ['error']) { case 1: print '

The file is bigger than this PHP installation allows

'; break; case 2: print '

The file is bigger than this form allows

'; break; case 3: print '

Only part of the file was uploaded

'; break; case 4: echo '

No file was uploaded

'; break; } } ?>

I get nothing except the echo of “stage 1”

Tried other versions and get messages such as

Warning: move_uploaded_file(… …): failed to open stream: No such file or directory in …getfile.php and
Warning: move_uploaded_file(): Unable to move 'C:\Windows\temp…

All points to a problem with move_uploaded_file but I cannot see why - have checked permissioning and everything else.

Using Heart Internet they are helpful in concept but don’t have an answer.

As I say I have used this method for years with no problem and just cannot see what is wrong .

I see a few issues, but nothing that I can be 100% sure of. So, this is the script I generally modify for file uploads:

[php]<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = ‘/var/www/uploads/’;
$uploadfile = $uploaddir . basename($_FILES[‘userfile’][‘name’]);

echo ‘

’;
if (move_uploaded_file($_FILES[‘userfile’][‘tmp_name’], $uploadfile)) {
echo “File is valid, and was successfully uploaded.\n”;
} else {
echo “Possible file upload attack!\n”;
}

echo ‘Here is some more debugging info:’;
print_r($_FILES);

print “

”;

?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service