The most viewed posts

How to clean up Windows Computer

About Desktop Icons in Windows Computer

Driver Booster

CCleaner

some (JavaScript Array Method)

Advanced System Care

Myanmar font and keyboard for Windows

Registry Reviver

How to sell IT materials in zilastar.com

How to make a computer secure and run faster

The most viewed items

Desktop Hard Disk

Dell Inspiron 5559

HP ProBook 430

SONY Playstation Portable

Laptop RAM

External Hard Disk

Laptop

ZilaStar ICT Jun 18 2019, 21:44:35
Category : php tutorials

Codes for file upload in php (step4)

We can set the limitations in uploading files. For example, we allow to upload only jpg or jpeg images and the maximum file size is 800KB.

<?php
@$name = $_FILES['file']['name'];
@$type = $_FILES['file']['type'];
@$size = $_FILES['file']['size'];

@$extension = substr($name, strpos($name, '.')+1);
@$max_size = 800000;

@$tmp_name = $_FILES['file']['tmp_name'];
@$location = 'tnw87/';


if(isset($name) && !empty($name)){
if($extension == 'jpg' || $extension == 'jpeg'){
 if($size < $max_size){
 if(move_uploaded_file($tmp_name, $location.$name)){
  echo 'Successfully uploaded!';
 }else{
  echo 'Upload Errors!';
 }
 }else{
  echo 'The maximum file size is 800KB';
 }
}else{
 echo 'Only jpg or jpeg image is allowed!';
}
}else{
 echo 'Please choose a file to upload';
}

?>

<form action = "upload.php" method = "POST" enctype = "multipart/form-data">
<input type = "file" name="file"><br /><br />
<input type = "submit" value = "Submit">
</form>

  • Comments:

    No comment to show.

    To Contact
    Available Services
    Terms and Conditions