Jump to content

PhP to upload files to a server


FreeBenzine

Recommended Posts

Hi,

I am working on a script to allow anonymous users to upload files. I started with this simple code, which sadly I cannot make to work:

 

<?php

$uploaddir = 'uploads/';

$uploadfile = $uploaddir . basename($_FILES['Upfile']['name']);

 

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

echo "File is valid, and was successfully uploaded.\n";

} else {

echo "File uploading failed.\n";

}

?>

 

The corresponding form is:

 

<form name="upload" action="Upload.php" method="POST" ENCTYPE="multipart/formdata">

Select the file to upload: <input type="file" name=Upfile">

<input type="submit" name="upload" value="upload">

</form>

 

I have not yet included the security codes, still it does not work. The message I receive is: "File uploading failed". The server does allow anonymous uploads. Do I need to edit the .htaccess file? Any tips will be greatly appreciated.

 

Is there some better guide than http://www.scanit.be/uploads/php-file-upload.pdf on the security of file uploads?

 

Cheers

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...