PHP File Upload

Simple File Upload
A Simple File Upload Form


File Upload Script
File Upload Script

<?php
if ( isset( $_FILES[‘file’] ) ) {
print “Name Of File: “. $_FILES[‘file’][‘name’] .”
“;
print “size Of file: “. $_FILES[‘file’][‘size’] .” bytes
“;
print “temp name: “.$_FILES[‘file’][‘tmp_name’] .”
“;
print “type: “. $_FILES[‘file’][‘type’] .”
“;
print “error: “. $_FILES[‘file’][‘error’] .”
“;
if ( $_FILES[‘file’][‘type’] == “image/gif” )
{
$source = $_FILES[‘file’][‘tmp_name’];
$target = “upload/”.$_FILES[‘file’][‘name’];
move_uploaded_file( $source, $target );
$size = getImageSize( $target );
$imgstr = “ $imgstr .= “src=\”$target\” alt=\”uploaded image\” />”;
print $imgstr;
}
}
?>

File Uploader
index.htmlFile Uploader

File Upload

Select a file to upload:


upload.php <?php
if( $_FILES[‘file’][‘name’] != “” )
{
copy ( $_FILES[‘file’][‘tmp_name’],
“C:/xampp/htdocs/” . $_FILES[‘file’][‘name’] )
or die( “Could not copy file” );
}
else
{
die( “No file specified” );
}
?>Upload complete

File upload succeeded…

  • Sent: <?php echo $_FILES[‘file’][‘name’]; ?>
  • Size: <?php echo $_FILES[‘file’][‘size’]; ?> bytes
  • Type: <?php echo $_FILES[‘file’][‘type’]; ?>

Click here to view file

 

Leave a Reply

Your email address will not be published. Required fields are marked *