Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
* * * * - 1 votes

How to create and upload file with php?

php zip work with php zip file

Best Answer surajkumardotin, 08 September 2015 - 11:38 PM

// Define function for uploading image
	function upload_multiple_images($images_array,$images_tmp,$images_size,$dir){
		$res=array();
 
		// extension array
		$ext=array('png','jpg','gif','jpeg','bmp');
 
		// Define size of image in kb
		$size=2000;
 
		// Count images
		$total_images=count($images_array);
		$res['total_uploaded_images']=$total_images;
 
		// check directory exist or not
		if(file_exists($dir)){
			// loop over image
			$count=0;
			foreach($images_array as $single_image){
				// Get image extension
				$image_ext=pathinfo($single_image,PATHINFO_EXTENSION);
 
				// Check image is valid or not
				if(in_array($image_ext,$ext)){
					// check size of each image
					$image_size=round($images_size[$count]/1000);
					if($image_size>$size){
						$res[$single_image][]='This has exceed limit of maximum size.';
					}else{
						$res['filesize'][]=$image_size;
						// rename image if exist else upload in folder
						if(file_exists($dir.'/'.$single_image)){
							// create random number
							$rand_num=rand(101,99999);
							$single_image=$rand_num.'_'.$single_image;
							// upload file on server
							move_uploaded_file($images_tmp[$count],$dir.'/'.$single_image);
							$res[$single_image][]='file has been uploaded';
						}else{
							// upload file on server
							move_uploaded_file($images_tmp[$count],$dir.'/'.$single_image);
							$res[$single_image][]='file has been uploaded';
						}
					}
				}else{
					$res['msg']='Image is not valid.';
				}
				$count++;
			}
		}else{
			$res['msg']=$dir.' directory doesn\'t exist.';
		}
 
		return $res;
	}

You can see the full source code at the following link

 

Upload multiple images with php

Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 surajkumardotin

surajkumardotin

    CC Regular

  • Member
  • PipPipPip
  • 29 posts

Posted 18 August 2015 - 11:47 PM

I want to know that how to upload and extract zip file with php? Is there any specific php library?



#2 surajkumardotin

surajkumardotin

    CC Regular

  • Member
  • PipPipPip
  • 29 posts

Posted 08 September 2015 - 11:38 PM   Best Answer

// Define function for uploading image
	function upload_multiple_images($images_array,$images_tmp,$images_size,$dir){
		$res=array();
 
		// extension array
		$ext=array('png','jpg','gif','jpeg','bmp');
 
		// Define size of image in kb
		$size=2000;
 
		// Count images
		$total_images=count($images_array);
		$res['total_uploaded_images']=$total_images;
 
		// check directory exist or not
		if(file_exists($dir)){
			// loop over image
			$count=0;
			foreach($images_array as $single_image){
				// Get image extension
				$image_ext=pathinfo($single_image,PATHINFO_EXTENSION);
 
				// Check image is valid or not
				if(in_array($image_ext,$ext)){
					// check size of each image
					$image_size=round($images_size[$count]/1000);
					if($image_size>$size){
						$res[$single_image][]='This has exceed limit of maximum size.';
					}else{
						$res['filesize'][]=$image_size;
						// rename image if exist else upload in folder
						if(file_exists($dir.'/'.$single_image)){
							// create random number
							$rand_num=rand(101,99999);
							$single_image=$rand_num.'_'.$single_image;
							// upload file on server
							move_uploaded_file($images_tmp[$count],$dir.'/'.$single_image);
							$res[$single_image][]='file has been uploaded';
						}else{
							// upload file on server
							move_uploaded_file($images_tmp[$count],$dir.'/'.$single_image);
							$res[$single_image][]='file has been uploaded';
						}
					}
				}else{
					$res['msg']='Image is not valid.';
				}
				$count++;
			}
		}else{
			$res['msg']=$dir.' directory doesn\'t exist.';
		}
 
		return $res;
	}

You can see the full source code at the following link

 

Upload multiple images with php






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download