• 0

[PHP] Upload file Via php?


Question

I am attempting to write a script that will upload an excel document (or any file for that matter) via a web form.

I have apache installed on a Windows 2000 Server. Here is the code I am using.

No files are appearing in the folder selected. I went through properties on the folder and told it everyone has all rights for read and write.

Also there is no need for security as there is only 1 person accessing this and it is for internal company use only.

What am I doing wrong?

FORM

<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

upload.php

<?php
$uploaddir = "uploads";
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
}
print "Your file has been uploaded successfully!";
?>

Inside the directory of these two files is the upload directory

Main directory

+uploads

form.php

upload.php

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

http://www.tizag.com/phpT/fileupload.php

$uploaddir = "uploads/";
$uploaddir = $target_path . basename( $_FILES['file']['name']); 

Try adding that. It changes the path to "uploads/filename.ext" instead of "uploads"

edit: Your html and php names don't match

Choose a file to upload: <input name="uploadedfile" type="file" /><br />

$_FILES['file']['tmp_name']

The name should be the same. Either change "uploadfile" to "file" in the HTML or change all references of "file" in your php code to "uploadfile"

Link to comment
Share on other sites

  • 0

<?php
$uploaddir = "uploads";
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES[
'file']['name']);
}
print "Your file has been uploaded successfully!";
?>

Should be;

<?php
$uploaddir = "uploads";
if(is_uploaded_file($_FILES['uploadedFile']['tmp_name']))
{
move_uploaded_file($_FILES['uploadedFile']['tmp_name'],$uploaddir.'/'.$_FILES[
'file']['name']);
}
print "Your file has been uploaded successfully!";
?>

There might be other errors, but that one jumped out at me :laugh:

If you still have problems, read through this. Their example is the same thing as what you're trying to do.

Link to comment
Share on other sites

  • 0

OK I tried to use the code from the php page and am not getting an error for every thing I attempt to upload.

form

<form enctype="multipart/form-data" action="upload.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="10000" />
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

update.php

<?php
$uploaddir = 'uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
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 "</pre>";

?>

Error

Possible file upload attack!

Here is some more debugging info:Array

(

[userfile] => Array

(

[name] => document.pdf

[type] =>

[tmp_name] =>

[error] => 2

=> 0

)

)

not entirely sure what the problem is.

Link to comment
Share on other sites

  • 0

Turns out that error was caused by the file size being to large, so i attempted using the actual file for the use of this project and received the following error.

And the file does not exist in the file I told it to go.

Possible file upload attack!
Here is some more debugging info:Array
(
    [userfile] => Array
        (
            [name] => example.xls
            [type] => application/vnd.ms-excel
            [tmp_name] => C:\Documents and Settings\-username-\Local Settings\Temp\php2A.tmp
            [error] => 0
            [size] => 162304
        )

)


Link to comment
Share on other sites

  • 0

I managed to get it functioning still produces an error message however, it now uploads the file to the directory, thank you for the assistance.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.