Jump to content

simple upload script isn't working..


josiahstaggs

Recommended Posts

<? if ((($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["files"]["type"] == "image/gif") || ($_FILES["files"]["type"] == "image/png")) && ($_FILES["files"]["size"] > 300000000))
{
 if ($_FILES["files"]["error"] > 0)
 	{
	 echo "Error: " . $_FILES["file"]["error"] . "<br />";
	}
 else 
 	{
	 if (file_exists("upload/" . $_FILES["file"]["name"]))
	 	{
		 echo "Sorry, this file already exists on the server";
		}
	 else
	 {
	  move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
	  echo "stored in upload/" . $_FILES["file"]["name"];
	 }
	}

}//end all IFs for this loop
else
{
 echo "Only JPEG, GIF or PNG are allowed. 3mb upload limit.";
}
?>

 

Keeps returning the first echo "Only JPEG, GIF or PNG are allowed. 3mb upload limit.".

Link to comment
https://forums.phpfreaks.com/topic/152191-simple-upload-script-isnt-working/
Share on other sites

Thanks, i fixed the variable issue but i'm still getting the same result.

 

my updated code.

<? if ((($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] > 300000000))
{
 if ($_FILES["file"]["error"] > 0)
 	{
	 echo "Error: " . $_FILES["file"]["error"] . "<br />";
	}
 else 
 	{
	 if (file_exists("upload/" . $_FILES["file"]["name"]))
	 	{
		 echo "Sorry, this file already exists on the server";
		}
	 else
	 {
	  move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
	  echo "stored in upload/" . $_FILES["file"]["name"];
	 }
	}

}//end all IFs for this loop
else
{
 echo "Only JPEG, GIF or PNG are allowed. 3mb upload limit.";
}
?>

A file upload screen can be built by creating a special form which looks something like this:

 

<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="__URL__" 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="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

 

url

http://uk.php.net/manual/en/features.file-upload.post-method.php

 

i ask for the form but hay here it is properly formatted for uploading files

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.