Jump to content

File Upload Using Php


kylebuch8
 Share

Recommended Posts

Hi,

 

I've been having a lot of trouble uploading files from an HTML form to a directory on my server. I have set all of the appropriate permissions to 777 and I have used code from other topics on this forum to try to make this work.

 

Here is the code that I am using for my HTML form.

 

<form enctype="multipart/form-data" method="post" action="upload.php">

 

Send this file: <input name="userfile" type="file"><br>

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

 

 

</form>

 

 

Here is the code that I am using for upload.php. I have taken out my user name where all of the *'s are.

 

<?php

 

$uploadDir = '/home/********/public_html/images/';

$uploadFile = $uploadDir . basename($_FILES['userfile']['name']);

 

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

{

echo "File {$_FILES['userfile']['name']} was uploaded successfully.\n";

}

else {

echo "Upload Failed!\n";

}

?>

 

 

Here are the error messages that I am receiveing:

 

Warning: move_uploaded_file(/home/********/public_html/images/aap_dyk_issue9_img1.gif) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/*******/public_html/upload.php on line 6

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpFbCAfc' to '/home/********/public_html/images/aap_dyk_issue9_img1.gif' in /home/********/public_html/upload.php on line 6

Upload Failed!

 

I have been all over this forum and other tutorials for the past week and I still cannot get this to work. The error that I have been receiving from most of my attempts using a lot of different code seem to be around using "move_uploaded_file()". Any help on this would be appreciated. Thanks.

Link to comment
Share on other sites

When you get it to work, be sure to disallow search engine robots from accessing the directory where the uploaded files are, or you'll be inundated with spammy pages quickly!

 

There is a script made for file uploads that you could use. Just search for it.

 

Also, the more scripts you have, the more holes you put in your site, and the more risk there is of a hacker gaining control over your site.

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.

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.

 Share

×
×
  • Create New...