Jump to content

upload file problem


Miko

Recommended Posts

Hi,

 

I can't believe after more then a year I'm stuck with the simplest upload script.

 

Here's my code:

 

<?php

if( isset($_POST['upload']) ){

	$uploaddir = "uploads/";
	$uploadfile = $uploaddir.$_FILES['fileupload']['name'];

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

		echo "Upload OK!";

	}else{

		echo "Upload FAILED!!!";

	}

}else{

?>

<form action="<?php $_SERVER['PHP_SELF'] ?>" name="upload" method="post">

<input type="file" name="fileupload" />
<input type="submit" name="upload" value="upload" />

</form>

<?php

}

?>

 

this is the simplest php upload script that you can find, though the least secure one :D (it's for a local pc project).

When I try to upload any file it gets to my else statement.

 

Anyone an idea why? I don't see it :(

 

Thanks!

Link to comment
Share on other sites

Your code is not checking for any of the possible upload errors before attempting to move the uploaded file, so it is not able to tell you why the upload is failing and neither can we.

 

You should both be doing this on a system with error_reporting set to E_ALL and display_errors set to ON so that all the php detected errors will be reported and displayed AND you need error checking and error reporting logic in your code to test if the upload was successful before attempting to access any for the uploaded file information.

 

Doing the above would tell you that none of your $_FILES['fileupload'][...] variables are set. When you backtrack this problem to your form, you  will find that the <form> tag is missing the enctype= attribute necessary to upload files.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.