Please login to start chat

ICT Solutions 2019-02-06 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.

Available Services
Download Android Application