Forum Moderators: coopster

Message Too Old, No Replies

help needing for creating a uploading script

         

An156

10:29 am on Apr 25, 2009 (gmt 0)

10+ Year Member



hello all..
i need help regarding uploading files on the server.

here is my code:

======================================================
<?php
if(!isset($_REQUEST['upld']))
{ ?><form enctype="multipart/form-data" action="work_details.php" method="POST">
<table border=1 cellspacing="0" cellpadding="5" width="560"><td align="center"><table>
<tr><td>Upload Worksheet</td><td><input name="file" type="file" size="20"/></td></tr>
<tr><td></td><td><input type="submit" value="Upload" name="upld" /></td></tr></table>
<?php
}
else
{ $target = "upload/";
$target = $target . basename( $_FILES['file']['name']) ;
if(move_uploaded_file($_FILES['file']['tmp_name'], $target))
{ echo "The file ". basename( $_FILES['file']['name']). " has been uploaded";
}
else
{ echo "Sorry, there was a problem uploading your file.";
}
}

?>

==============================================

Please help
Anand :)

[edited by: An156 at 10:37 am (utc) on April 25, 2009]

dreamcatcher

8:45 am on Apr 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Anand.

You don`t actually say what your problem is. Do you see errors? Are your permissions set on your target directory correctly? Does the value of $target contain the correct path?

dc

An156

3:36 pm on Apr 26, 2009 (gmt 0)

10+ Year Member



hi dc!
actually m facing problem in uploading the file thru the same page.
suppose m having the page "upload.php" which has an upload box name="abc" and when i tried to retrieve the file by this code
$target = $target . basename( $_FILES['abc']['name'])
then it gives an error of undefined index abc

but when i tried by seperating the upload box code in a simple up.html and targeting it to upload.php then it works. how i can do the both things on the same page?

Plz help

coopster

10:56 pm on Apr 27, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Check to see if the Submit button was sent along by checking for it's existence in the $_POST superglobal.