The list of all PHP and Mysql posts

How to upload a file

example:

code:

<?php
$file_dir = "/folder default name to upload from";
$file_url ="a url that shows where the file has been uploaded to .i.e http://www.myserver.com/vahid/uploads";
if ( isset( $fupload ) )
{
print "path: $fupload<br>\n";  // the folder of the file that is uploaded
print "name: $fupload_name<br>\n"; // the name of the file that is uploaded
print "size: $fupload_size bytes<br>\n"; // the size of the file that is uploaded
print "type: $fupload_type<p>\n\n"; // the type of the file that is uploaded
if ( $fupload_type == "image/gif" )
{
copy ( $fupload, "$file_dir/$fupload_name") or die ("Couldn't copy");
print "<img src=\"$file_url/$fupload_name\"><p>\n\n";
}
}
?>
<form enctype="multipart/form-data" action="<?php print $PHP_SELF?>" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="51200">
<input type="file" name="fupload"><br>
<input type="submit" value="Send file!">
</form>

The order of  "enctype="multipart/form-data opens a dialog box to upload a file. The variable MAX_FILE_SIZE assigns the maximum allowed size for uplouding.
Then the assigned file is sent to this page again and the command "copy" copies the file to the server and shows a url for it.

1 comment:

  1. Thnaks for providing neat content.. I am very happy as i found thiblog. i found your site in google search while searching for my web designing companies in karimnagar website.. Its nice thanks...

    ReplyDelete