This is the Simple file upload code in php with html form
First of all you create a html form index.php for file upload code in php with html form
<?php
if ( isset( $_FILES['fileupload'] ) ) {
print "name: ". $_FILES['fileupload']['name'] ."<br />";
print "size: ". $_FILES['fileupload']['size'] ." bytes<br />";
print "temp name: ".$_FILES['fileupload']['tmp_name'] ."<br />";
print "type: ". $_FILES['fileupload']['type'] ."<br />";
print "error: ". $_FILES['fileupload']['error'] ."<br />";
if ( $_FILES['fileupload']['type'] == "image/gif" ) {
$source = $_FILES['fileupload']['tmp_name'];
$target = "upload/".$_FILES['fileupload']['name'];
move_uploaded_file( $source, $target );// or die ("Couldn't copy");
$size = getImageSize( $target );
$imgstr = "<p><img width=\"$size[0]\" height=\"$size[1]\" ";
$imgstr .= "src=\"$target\" alt=\"uploaded image\" /></p>";
print $imgstr;
}
}
?>
First of all you create a html form index.php for file upload code in php with html form
<form action="upload.php" enctype="multipart/form-data" method="post"> <input name="fileupload" type="file" /> <input type="submit" value="upload!" /> </form>Now you create a action file upload.php file upload code in php with html form.
<?php
if ( isset( $_FILES['fileupload'] ) ) {
print "name: ". $_FILES['fileupload']['name'] ."<br />";
print "size: ". $_FILES['fileupload']['size'] ." bytes<br />";
print "temp name: ".$_FILES['fileupload']['tmp_name'] ."<br />";
print "type: ". $_FILES['fileupload']['type'] ."<br />";
print "error: ". $_FILES['fileupload']['error'] ."<br />";
if ( $_FILES['fileupload']['type'] == "image/gif" ) {
$source = $_FILES['fileupload']['tmp_name'];
$target = "upload/".$_FILES['fileupload']['name'];
move_uploaded_file( $source, $target );// or die ("Couldn't copy");
$size = getImageSize( $target );
$imgstr = "<p><img width=\"$size[0]\" height=\"$size[1]\" ";
$imgstr .= "src=\"$target\" alt=\"uploaded image\" /></p>";
print $imgstr;
}
}
?>
No comments:
Post a Comment