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
https://forums.phpfreaks.com/topic/217761-upload-file-problem/
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
https://forums.phpfreaks.com/topic/217761-upload-file-problem/#findComment-1130331
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.