Jump to content

Problems with a php upload script


predator

Recommended Posts

Hi i have been looking on the forums for a while now and cannot find the answer i need.

 

i have the following upload script

 

$target = "uploaded/".$_FILES['fileUp']['name'];

 

if(move_uploaded_file($_FILES['fileUp']['tmp_name'], $target))

{

echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";

}

else {

echo "Sorry, there was a problem uploading your file.";

}

 

and the following html submit form

 

<form enctype="multipart/form-data" method="POST" action="Upload.php">

<br />

<input name="fileUp" type="file"/>

<br />

<br />

<input type="submit" value="Upload File"/>

</form>

 

however when i hit submit to take it to the upload page i get the errors of

 

 

Notice: Undefined index: fileUp in c:\inetpub\wwwroot\Sites\TNL New\uploader\Upload.php on line 3

 

Notice: Undefined index: fileUp in c:\inetpub\wwwroot\Sites\TNL New\uploader\Upload.php on line 5

 

i just cannot work out why. the file input box is called fileUp but get it still gives me this error please can anyone help i have been racking me brain over this for ages and from what i can see it should just work.

 

thanks for help in advance

 

regards

Mark

Link to comment
https://forums.phpfreaks.com/topic/42913-problems-with-a-php-upload-script/
Share on other sites

That is just a notice, it does not mean anything other than stating that fileUp is not an index of the array $_FILES.

 

The reason is you have no logic to check if the form was submitted.

 

I would do a check such as:

 

if (isset($_FILES['fileUp'])) {
$target = "uploaded/".$_FILES['fileUp']['name'];

if(move_uploaded_file($_FILES['fileUp']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
}else {
?>
<form enctype="multipart/form-data" method="POST" action="Upload.php">


<input name="fileUp" type="file"/>




<input type="submit" value="Upload File"/>
</form>
<?php
}

 

I would probably just hide the notices if it is working via http://us3.php.net/manual/en/function.error-reporting.php

 

Notices do not necessarily mean anything. It is the warning and FATAL ERRORs that you have to watch out for.

thanks for the swift reply

 

however when i run my script it does come up as

 

Sorry, there was a problem uploading your file.

 

why would it come up with this if all i can see is that the information is correct if i echo $_FILES['uploadedfile']['name'];

 

that also comes up as nothing like nothing has even been passed through from the form.

regards

Mark

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.