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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

right just checked and made sure they are all uploadedfile and also the file input is uploadedfile as well but still with a simple check it shows that no file is being passed from the form to the actual upload script.

 

regards

Mark

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.