0

I have an image uploader and I'm trying to make the site display what type of option has been selected when the file is uploaded. I will later add this functionality to connect to different tables in a database, but for now I just want it printing out what option has been selected.

Here is my upload. html:

<body>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="400000" />
Choose a file to upload:
<br />
<br />
<input name="uploadedfile" type="file" />
<br />
<select name = "uploadType">
<option value="Picture">Picture</option>
<option value="Video">Video</option>
<option value="Fact">Fact</option>
</select>
<br />
<br />
<input type="submit" value="Upload File" />
</form>
</body>

And here is my uploader. php:

$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";

if (uploadType == "Picture"){
echo "\nYou have uploaded a picture.";

} if (uploadType == "Video"){
echo "\nYou have uploaded a video.";
} if (uploadType == "Fact"){
echo "\nYou have uploaded a fact.";
} else{
echo "\nuploadType fail!";
}

} else{
    echo "There was an error uploading the file, please try again!";
}

Every time I try to upload it just comes up with the "uploadType fail!" message. What am I doing wrong?

Any help would be greatly appreciated!

Thank you so much!

2
  • And that's why you turn on error reporting during development, because that would complain about an undefined constant "uploadType"... Commented May 8, 2012 at 23:59
  • Just a heads up 400000 is 400kb or just under 1/2 a megabyte, dont confuse it for 4mb or 40mb. MAX_FILE_SIZE is in bytes Commented May 9, 2012 at 0:08

3 Answers 3

2
$uploadType = $_POST["uploadType"];

Then use $uploadType in your if statements. Variables in PHP always begin with a dollar sign.

In addition, use else if for the other conditions.

Sign up to request clarification or add additional context in comments.

1 Comment

Works great, I should have known, I just wasn't sure on the exact syntax. Thank you so much!
1

You are missing two 'else' statements - before the video and before the fact 'if' statement.

1 Comment

Unless you choose "Fact", the fail message will always appear.
0

uploadType is being used as a constant here. Try replacing uploadType with $_POST['uploadType'].

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.