Please Help. Uploading Files, I have spent so long trying...

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!

Moderator: General Moderators

Post Reply
boon4376
Forum Newbie
Posts: 19
Joined: Sun Oct 01, 2006 9:55 pm

Please Help. Uploading Files, I have spent so long trying...

Post by boon4376 »

I have no idea why this isnt working. Perhapse it is because I do not have much experience with PHP, I made it through my PHP for teens book, so i know how the language works.. but i cant seem to get this to work...

Its funny everywhere i go, sites all say it is simple, and the code is all so similar between sites for uploading files to the server...

Anyways, i am trying code from this here http://us2.php.net/features.file-upload and it wont work. I get the error "Possible file upload attack!" ... Heres the code i am using exactly, maybe if you find whats wrong with it you can help me.

for the form:

Code: Select all

<html>
<head>
<title>File Upload Form</title>
</head>
<body>

<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="uploadpro.php" method="POST">

    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />

    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="uploadFile" type="file" />

    <input type="submit" value="Send File" />


</form>


</body>
</html>

Code: Select all

<?php


$uploaddir = '/upload';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['uploadFile']['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 "</pre>";

?>
I have literally spent days just trying to make uploads to my server possible... any help is very much appriciated!
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post by wtf »

your

Code: Select all

if (move_uploaded_file($_FILES['uploadFile']['tmp_name'], $uploadfile)) {


shoud read

Code: Select all

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {

you also need to have upload directory
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Change this:

Code: Select all

$uploaddir = '/upload';
into this:

Code: Select all

$uploaddir = '/upload/';
if you want it to upload the files to the 'upload' directory.

P.S I didn't check the rest of the code.
Post Reply