jquery+php+ajax显示上传进度的多图片上传并生成缩(3)

<?php 
/*
    @@ Including the functions.php for using the necessary functions.
*/ 
include('functions.php'); 
 
/*
    @@ This is the file upload class which does all the uploading work.
*/ 
include('class.upload.php'); 
 
if(isset($_FILES["file"])) { 
    /*
        @@ Generating unique name for the photo.
    */ 
    $time = time(); 
    $rand_1 = rand(999, 999999); 
    $rand_2 = rand(999999, 999999999); 
    $rand_3 = rand(); 
    $unique_value = $time.'_'.$rand_1.'_'.$rand_2.'_'.$rand_3; 
 
    /*
        @@ Folder creation for each and every day. This ensures performance even with millions of images.
    */ 
    $folder = date('zY'); 
        if(substr($folder, 0) == 0) { 
            $folder = '367'.date('Y'); 
        } 
 
    /*
        @@ This folder is for the source image files.
    */ 
    $pfolder = 'https://www.jb51.net/upload/source/';  
        if(!is_dir($pfolder)) { 
            mkdir($pfolder, 0755); 
        } 
 
    /*
        @@ This folder is for the image files with 120x120 dimensions.
    */ 
    $tfolder = 'https://www.jb51.net/upload/small/'; 
        if(!is_dir($tfolder)) { 
            mkdir($tfolder, 0755); 
        } 
 
    /*
        @@ Assigning the upload file to the upload class for all the processing.
    */ 
    $handle = new Upload($_FILES["file"]); 
        if($handle->uploaded) { 
            $extension = $handle->file_src_name_ext; 
            $mime = $handle->file_src_mime; 
 
                if(($mime == 'image/gif') || ($mime == 'image/jpg') || ($mime == 'image/png') || ($mime == 'image/bmp') || ($mime == 'image/pjpeg') | ($mime == 'image/jpeg')) { 
                    /*
                        @@ Check if the uploaded filetype is an image or not.
                    */ 
                    if(($extension == 'gif') || ($extension == 'jpg') || ($extension == 'jpeg') || ($extension == 'png') || ($extension == 'bmp') || ($extension == 'pjpeg')) { 
                        if($handle->image_src_x > 500) { 
                                /*
                                    @@ Check if the filesize is smaller than 10 MB. 10 MB = 10485760 bytes.
                                */ 
                            if($handle->file_src_size < 10485760) { 
                                /*
                                    @@ Getting the actual file name (with and without extension) and sanitizing it for inserting in the database.
                                */ 
                                $real_name = clean_input($handle->file_src_name); 
                                $body_name = clean_input($handle->file_src_name_body); 
 
                                $handle->file_new_name_body = $unique_value.'_'.$body_name; 
                                $handle->Process($pfolder); 
 
                                $handle->image_resize = true; 
                                $handle->image_ratio_crop = 'T'; 
                                $handle->image_y = 120; 
                                $handle->image_x = 120; 
                                $handle->file_new_name_body = $unique_value.'_'.$body_name; 
                                $handle->Process($tfolder); 
 
                                    if($handle->processed) { 
                                        $actual_name = $handle->file_dst_name; 
                                        $size = ceil($handle->file_src_size / 1024); 
 
                                        ## Sending photo details back to the uploader. 
                                        $date = date("c", $time); 
 
                                            ## Reducing the length of real name if it exceeds 50 characters. 
                                            if(strlen($real_name) > 50) { 
                                                $real_name = substr($real_name, 0, 50).'..'; 
                                            } 
                                            echo 'success,'.$real_name.','.$date.','.$folder.','.$actual_name; 
                                    } else { 
                                        echo 'error,<div><strong>Upload Error</strong><br/>There was an error uploading the photo.</div>'; 
                                    } 
                            } else { 
                                echo 'error,<div><strong>Upload Error</strong><br/>The photo is bigger than the allowed upload size of <strong>10MB</strong>.</div>'; 
                            } 
                        } else { 
                            echo 'error,<div><strong>Upload Error</strong><br/>You are trying to upload a photo with smaller dimensions.</div>'; 
                        } 
                    } else { 
                        echo 'error,<div><strong>Upload Error</strong><br/>Only photo uploads are allowed.</div>'; 
                    } 
                } else { 
                    echo 'error,<div><strong>Upload Error</strong><br/>Only photo uploads are allowed.</div>'; 
                } 
        } else { 
            echo 'error,<div><strong>Upload Error</strong><br/>An upload error occured.</div>';            
        } 
    /*
        @@ Return the json response to the script.
    */ 
    $handle->Clean(); 
} else { 
    echo 'error,<div><strong>Upload Error</strong><br/>An upload error occured.</div>'; 
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/dc42ed775b32cd3f43a16376c7cb8932.html