PHP Scripting

Upload File

PHP script for upload image and file

6/9/2020
0 views
upload-file.phpPHP
<html>
	<head>
 		<title>Upload File</title>
	</head>
	<body>
	
		/* Encoded form data for uploading a file */
		<form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
 			<input type="file" name="up_file" id="up_file" />
 			<input type="submit" value="upload" />
 		</form>
 		
 		<?php
 			if(isset( $_FILES['up_file'])){
				echo "Name: ".     $_FILES['up_file']['name']       ."<br />";
				echo "Size: ".     $_FILES['up_file']['size'] ." bytes<br />";
				echo "Temp name: ".$_FILES['up_file']['tmp_name']   ."<br />";
				echo "Type: ".     $_FILES['up_file']['type']       ."<br />";
				echo "Error: ".    $_FILES['up_file']['error']      ."<br />";

				/* Upload file if it's a images */
				if($_FILES['up_file']['type'] == "image/jpeg" ) {
					$source = $_FILES['up_file']['tmp_name'];
					$target = "upload/".$_FILES['up_file']['name'];
					
					/*  Moves an uploaded file to a new location */
					if(move_uploaded_file($source, $target)) {
						$size = getImageSize( $target );
						echo '<img width="'.$size[0].'" height="'.$size[1].'" src="'.$target.'" alt="uploaded image" /><br />';
						echo "Image Uploaded Successfully!";
					}
					else
						echo "Fail to upload!";
				}
				else
					echo "It's not a images!";
			}
 		?>
 	</body>
</html>



/* Output */
Input:
Choose a image file

Name: order05.jpg
Size: 197978 bytes
Temp name: /tmp/phphWY5Zn
Type: image/jpeg
Error: 0

Image Uploaded Successfully!
PHPupload file in phpupload file PHP script

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com