The most viewed posts

Registry Reviver

Contact Me

Web Development Services

Computer Repair and Maintenance Service

How to clean up Windows Computer

Driver Booster

About Desktop Icons in Windows Computer

CCleaner

How to make a computer secure and run faster

Myanmar font and keyboard for Windows

The most viewed items

Dell Inspiron 5559

Desktop Hard Disk

Laptop RAM

SONY Playstation Portable

HP ProBook 430

External Hard Disk

Laptop

Please login to start chat

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 Contact
    Available Services
    Terms and Conditions