Pic Handeler

This processes pics that are uploaded at post

function pic_handeler($uploaded_file,$members_ID) { // 629AM

            $image_folder = "member_images/".$members_ID;
			
			echo $uploaded_file['name'];

	        if (is_dir($image_folder) === false){
              mkdir($image_folder, 0777);
            }
			
			
			$allowed= array ('image/gif', 'image/jpeg', 'image/jpg', 'image/pjpeg', 'image/png');
			if (in_array($uploaded_file['type'], $allowed)) {
			
			$storeduploadedfile = $uploaded_file['tmp_name'];	
				
				switch ($uploaded_file['type']) {
						  
						  case "image/jpg":
							$this_file_type=".jpg";
							$src = imagecreatefromjpeg($storeduploadedfile);
							break;
							
						  case "image/gift":
							$this_file_type=".gif";
							$src = imagecreatefromgif($storeduploadedfile);
							break;	
							
						  case "image/jpeg":
							$this_file_type=".jpeg";
							$src = imagecreatefromjpeg($storeduploadedfile);
							break;
							
						  case "image/pjpeg":
							$this_file_type=".pjpeg";
							$src = imagecreatefromjpeg($storeduploadedfile);
							break;	
							
						  case "image/png":
							$this_file_type=".png";
							$src = imagecreatefrompng($storeduploadedfile);
							break;	
							
						  }// END THE SWITCH
						  
					list($width,$height)=getimagesize($storeduploadedfile);  
						  
					$tmp=imagecreatetruecolor(100,100);	
					
					
					imagecopyresampled($tmp,$src,0,0,0,0,100,100,
					
					 $width,$height);  
					 
					 
				
					$complete_new_file=$uploaded_file['name'];
					
					$named= $uploaded_file['name'];
					
					$thumb_filename = "member_images/$members_ID/thumb_{$named}";
					
					imagejpeg($tmp,$thumb_filename,100);
				
		
					if (move_uploaded_file($uploaded_file['tmp_name'], "member_images/$members_ID/$named")) {
						

					}
					
				
			}//END if (in_array($_FILES['file_to_upload']['type'], $allowed)) {	
			else {
				
			switch ($uploaded_file['error']) {
						  
						  case 1:
							$update_status="<div id=\"pic_update_div\" style=\"border-color:red;\"><span id=\"all_bad\">File is too big!</span></div>";
							break;
							
						  case 2:
							$update_status="<div id=\"pic_update_div\" style=\"border-color:red;\"><span id=\"all_bad\">File is too big!</span></div>";
							break;	
							
						  case 3:
							$update_status="<div id=\"pic_update_div\" style=\"border-color:red;\"><span id=\"all_bad\">File partialy loaded!</span></div>";
							break;
							
						  case 4:
							$update_status="<div id=\"pic_update_div\" style=\"border-color:red;\"><span id=\"all_bad\">No file was uploaded!</span></div>";
							break;	
							
						  case 6:
							$update_status="<div id=\"pic_update_div\" style=\"border-color:red;\"><span id=\"all_bad\">No temp folder available!</span></div>";
							break;
							
						  default:
							$update_status="<div id=\"pic_update_div\" style=\"border-color:red;\"><span id=\"all_bad\">Please upload a JPG or GIF!</span></div>";
							break;
						  }// END THE SWITCH
						  
		
				
			} // END ELSE FOR if (in_array($_FILES['file_to_upload']['type'], $allowed)) {
			
              
			 $full_image_src = "http://stlhungergames.com/member_images/$members_ID/thumb_{$named}";
			 
             return $full_image_src;

} // 629AM



function update_progress_images() { // 356AM


if (!empty($_FILES['upload_member_progress_pic_0']['name'])) {	
  $upload_member_progress_pic_0 = $_FILES['upload_member_progress_pic_0'];				  	  
  $week_0_member_progress_pic = pic_handeler($upload_member_progress_pic_0, $profile_id);			  				  
}


update_user_meta( $profile_id, 'member_fields', $member_fields );


} // 356AM



add_action( 'wp_loaded', 'update_progress_images' );


Comments