如何更改PHP中的图像文件大小限制

时间:2019-05-06 07:30:37

标签: php sql database image upload

//php code for uploading multiple images in php
<?php
$gid=$agid;
$gname=$aname;
$gdate = date('Y-m-d H:i:s');
$status='process';
include"connect.php";
$rd=rand();
if(isset($_FILES['upload1'])){
$errors= array();
foreach($_FILES['upload1']['tmp_name'] as $key => $tmp_name){
$file_name = $key.$rd.$_FILES['upload1']['name'][$key];
$file_size =$_FILES['upload1']['size'][$key];
$file_tmp =$_FILES['upload1']['tmp_name'][$key];
$file_type=$_FILES['upload1']['type'][$key];    

// FILE SIZE DESCRIPTION

if($file_size > 2097152){
$errors[]='File size must be less than 2 MB';
}           
$desired_dir="gupload";
if(empty($errors)==true){
if(is_dir($desired_dir)==false){
mkdir("$desired_dir", 'gupload');       
}
if(is_dir("$desired_dir/".$file_name)==false){

// DESCRIBE THE IMAGE DIMENTION 

$src = imagecreatefromjpeg($tmp_name);
list($width,$height)=getimagesize($tmp_name);
$newwidth=($width/$height)*150;
$newheight=150;
$tmp=imagecreatetruecolor($newwidth,$newheight);

//IMAGE MOVING TO GIVEN PATH OR FOLDER FROM TEMPERARY FILE imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$rd=rand();
$filename = "gcatch/".$file_name;
imagejpeg($tmp,$filename,100);
imagedestroy($src);
move_uploaded_file($file_tmp,"$desired_dir/".$file_name);
}else
{ 
// rename the file if another one exist

$new_dir="$desired_dir/".$file_name.time();
rename($file_tmp,$new_dir) ;                
}

//DATABASE INSERT QUERY
$query="INSERT into             
tbl_gallery(`gid`,`aid`,`gname`,`gimages`,`date`,`status`)           
VALUES('','$gid','$gname','$file_name','$gdate','$status')";
mysql_query($query);            
}
else
{
print_r($errors);       
}
}
if(empty($errors)){
echo " <div class='alert alert-success'>Your Photos Is Successfully     
Uploded. <a href='viewsgimages.php'>View Photos</a> |<a 
href='addevent.php'> Add new Photos</a></div>";
}

0 个答案:

没有答案