Total Pageviews

Thumbnail Generator in PHP + Saving + MYSQL

Folders
----------

Home.php
===========
here we are using dropzone...pls see dropzone articles in my blog.

  <!-- ==================== Dropzone Start============== -->
                    <form action="sql_php/post_wall.php" method="post" class="dropzone" id="my-awesome-dropzone" enctype="multipart/form-data">
                      <span class="dropzone-previews"></span>
                      <div class="fallback">
                        <input name="file" type="file" multiple/>
                      </div>
                    </form>
      <!-- ==================== Dropzone End============== -->



post_wall.php
===========


foreach((array)$_FILES['file']['name'] as $key => $tmp_name ){
    $file_name = $key.$_FILES['file']['name'][$key];
    $file_size =$_FILES['file']['size'][$key];
    $file_tmp =$_FILES['file']['tmp_name'][$key];
    $file_type=$_FILES['file']['type'][$key];


if(is_dir($dir)==false){

$path_name= "uploads/";



$status_id=$_SESSION['status_id'];


 $file = pathinfo($file_name);
$fileType = $file["extension"];
$desiredExt='jpg';
$fileNameNew_lg = "lg".rand(333, 999) . time() . ".$desiredExt";
move_uploaded_file($file_tmp,"../uploads/".$fileNameNew_lg);


$result= mysqli_query($db_conx,"INSERT INTO uploads (filename,path,user_id,status_id) VALUES ('".$fileNameNew_lg."','".$path_name."','".$u_id."','".$status_id."')" ) ;
$last_id = mysqli_insert_id($db_conx);

}



//=====================THUMBNAIL Start======================


ini_set("memory_limit", "99M");
ini_set('post_max_size', '20M');
ini_set('max_execution_time', 600);
define('IMAGE_SMALL_DIR', '../uploads/small/');
define('IMAGE_SMALL_SIZE', 50);
define('IMAGE_MEDIUM_DIR', '../uploads/medium/');
define('IMAGE_MEDIUM_SIZE', 250);
/*defined settings - end*/
$output['status']=FALSE;
set_time_limit(0);
$allowedImageType = array("image/gif",   "image/jpeg",   "image/pjpeg",   "image/png",   "image/x-png"  );


/*create directory with 777 permission if not exist - start*/

createDir(IMAGE_SMALL_DIR);
createDir(IMAGE_MEDIUM_DIR);

/*create directory with 777 permission if not exist - end*/

$path[0] = "../uploads/".$fileNameNew_lg;
$file = pathinfo($file_name);
$fileType = $file["extension"];
$desiredExt='jpg';




$desiredExt='jpg';
$fileNameNew_md = "md".rand(333, 999) . time() . ".$desiredExt";
$fileNameNew_sm = "sm".rand(333, 999) . time() . ".$desiredExt";


$path[1] = IMAGE_MEDIUM_DIR . $fileNameNew_md;
$path[2] = IMAGE_SMALL_DIR . $fileNameNew_sm;

if (createThumb($path[0], $path[1], $file_type, IMAGE_MEDIUM_SIZE, IMAGE_MEDIUM_SIZE,IMAGE_MEDIUM_SIZE)) {

if (createThumb($path[1], $path[2],"$desiredExt", IMAGE_SMALL_SIZE, IMAGE_SMALL_SIZE,IMAGE_SMALL_SIZE)) {
$output['status']=TRUE;
$output['image_medium']= $path[1];
$output['image_small']= $path[2];




$md_image="uploads/medium/". $fileNameNew_md;
$sm_image="uploads/small/". $fileNameNew_sm;

$result_thumbs= mysqli_query($db_conx,"update uploads set medium_thumbpath ='".$md_image."',medium_thumbname='".$fileNameNew_md."',small_thumbpath ='".$sm_image."',small_thumbname='".$fileNameNew_sm."'  where id='".$last_id."' ") ;
}
}



echo json_encode($output);

//=====================THUMBNAIL End======================

}



[ If you like my work please donate  :) you can see donate button on top left side ]