ASPN ActiveState Programmer Network  
ActiveState, a division of Sophos
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups
Submit Recipe
My Recipes

All Recipes
All Cookbooks


View by Category

Title: File Uploading in PHP BY ROHIT D'SOUZA
Submitter: rohit d'souza (other recipes)
Last Updated: 2006/05/05
Version no: 1.0
Category: Miscellaneous

 

Not Rated yet


Description:

This is a simple code for file uploading in php

Source: Text Source

<pre>
<form enctype="multipart/form-data" action="index.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
     <input type="submit" value="Send File" onClick="return checkfile(this.form);" />
</form>

write this code in the head section of your php in which you have written the above code.

<html>
<head>
<title>
</title>
<script langauge="javascript" >
function checkfile(form)
{

if (form.userfile.value == "")
{
alert('Please Select a File To Upload');

return false;
}
else
{
return true;
}


}
</script>

</head>


Now write this code in the action script i.e in my case it is index.php

$uploaddir = '/home/rohit/upload/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);


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

  echo "File is valid, and was successfully uploaded.\n";

}
 else

 {
   echo "file upload error\n";
}



Thats all
do mail me ur feedback at rajdsouza@yahoo.com










</pre>

Discussion:



Add comment

No comments.



Highest rated recipes:

1. Single Linked List

2. main - python-like if ...

3. iPHP: Semi-interactive ...

4. tinySendMail

5. Microsoft Access ...

6. DB_eSession PHP class ...

7. PHP MySQL Search Class

8. Pass Javascript arrays ...

9. Microsoft Access ...

10. Password generation




Privacy Policy | Email Opt-out | Feedback | Syndication
© 2006 ActiveState Software Inc. All rights reserved.