Jump to content

Upload Form


!!!!!

Recommended Posts

Okay, I am making an Upload form on my website for my use. I'm gonna have the page password-protected so that nobody but me or my friends can upload.

 

I would like to know what's wrong with these:

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

and

<?php 
$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
?>

 

I would also like to know how I can limit the extensions to what people can upload. Thanks!

 

EDIT: I get these errors:

Warning: move_uploaded_file(uploads/Untitled-1.gif): failed to open stream: Permission denied in /home/neomoonc/public_html/uploader.php on line 6

Warning: move_uploaded_file(): Unable to move '/var/tmp/phpHD4qlo' to 'uploads/Untitled-1.gif' in /home/neomoonc/public_html/uploader.php on line 6
There was an error uploading the file, please try again!

Link to comment
https://forums.phpfreaks.com/topic/58641-upload-form/
Share on other sites

http://w3schools.com/php/php_file_upload.asp try this

 

the error maybe say that the folder is not in the right mod

you may need chmod or change the mod of folder manually change into 777

=\

 

<?php
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/pjpeg")
&& ($_FILES["file"]["size"] < 1000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

and

<html>
<body>

<form action="uploader.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>

 

I still get almost the exact same thing. This time, under the errors, it says it worked. But then when I go into the file where I tried to move it, it's not there.

 

Errors:

 


Warning: move_uploaded_file(upload/Untitled-2.gif): failed to open stream: Permission denied in /home/neomoonc/public_html/uploader.php on line 24

Warning: move_uploaded_file(): Unable to move '/var/tmp/phpHD4qlo' to 'upload/Untitled-2.gif' in /home/neomoonc/public_html/uploader.php on line 24
Stored in: upload/Untitled-2.gif

Link to comment
https://forums.phpfreaks.com/topic/58641-upload-form/#findComment-290941
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.