在临时目录中超过70 kb图像不上传

时间:2013-06-20 06:20:26

标签: php mysql zend-framework image-uploading

我已经在服务器上完美地上传了70 kb以下的图像。管理服务器cpanel视图 已经设置了php.ini文件 max_upload =2000mb max-exe-time = 300 max input time =600 php.ini文件就可以了。 我的问题在70kb以上的图像无法移动临时目录
我不明白 即时通讯使用zend框架和java脚本

我的控制器代码

    public function changeImageProcessAction() {

    $this->_helper->layout->disableLayout();
    if ($this->getRequest()->isPost()) 
    {
        $file = $_FILES['file'];

        // DO NOT CHANGE BELOW
        $tempName = strtotime(date('Y-m-d H:i:s')); //$_SESSION["SESSION_TEMP_ARTIST_IMG_NAME"];
        $allowedImageTypes = explode(",", UPLOAD_ACCEPTED_MIME_TYPES);

        $fileSize = $file['size'];
        $fileType = $file['type'];
        $fileExt = strtolower(end(explode('.', $file['name'])));
        if (MAX_IMAGE_UPLOAD_SIZE< $fileSize) { // Check for Max File Size
            echo '{ "result" : "false",
                        "message"  : "The file is too big."}';              
        } else {
            if ($file['tmp_name'] != '') {  

                if (in_array($fileType, $allowedImageTypes)) {                      
                    $tempFile = SYSTEM_TEMP_DIRECTORY . "$tempName.$fileExt" ;
                    $session = new Zend_Session_Namespace(DEFAULT_SESSION_NAMESPACE);
                    $catID = $this->getRequest()->getPost('categoryID','');
                    if($catID == "")
                            $catID = $session->CURRENT_MAIN_CATEGORY_ID;

                    $imageLocation = MAIN_CATEGORY_IMAGE_PATH . "$catID.jpg";
                    // move file to the 'temp' folder
                    if (!file_exists($tempFile)) {
                        move_uploaded_file($file['tmp_name'],$tempFile);
                        if (file_exists($tempFile)) {   
                            list($width, $height) = getimagesize($tempFile);
                            if($width < IMAGE_CATEGORY_MAX_UPLOAD_WIDTH ||  $height < IMAGE_CATEGORY_MAX_UPLOAD_HEIGHT)
                            {
                                unlink($tempFile);
                                echo '{ "result" : "false",
                                        "message"  : "Invalid image dimensions."}'; 
                            }
                            else
                            {
                                $imageResult = Classes_ImageProcessor::cropImage($tempFile, $imageLocation, IMAGE_CATEGORY_IPHONE_WIDTH, IMAGE_CATEGORY_IPHONE_HEIGHT, $fileType);  

                                $imageLocation = MAIN_CATEGORY_IPAD_IMAGE_PATH . "$catID.jpg";
                                $imageResultIpad = Classes_ImageProcessor::cropImage($tempFile, $imageLocation, IMAGE_CATEGORY_IPAD_WIDTH, IMAGE_CATEGORY_IPAD_HEIGHT, $fileType);  

                                if($imageResult && $imageResultIpad )           
                                {
                                    $objCommon = new Classes_Common();
                                    $objCommon->setLastUpdatedTime("Image for category $catID is created");
                                    unlink($tempFile);
                                    $imagePath = LIVE_HOST_URL . MAIN_CATEGORY_IMAGE_PATH . $catID . '.jpg?' . time();
                                    echo '{"result" : "true", "name":"'.$file['name'].'", "type":"'.$file['type'].'", "size":"'.round($file['size']/1048576, 2).'Mb", "imagePath":"'."$imagePath".'", "newname":"'."$catID.jpg".'","message"  : "The image created successfully"}'; 
                                }
                                else
                                {
                                    unlink($tempFile);
                                    echo '{ "result" : "false",
                                        "message"  : "Image configuration failed"}';
                                }
                            }
                        } else {
                            echo '{ "result" : "false",
                                        "message"  : "Image saving failed"}';
                        }
                    } else {
                        echo '{ "result" : "false",
                                        "message"  : "The file already exists"}';
                    }
                } else {
                    echo '{ "result" : "false",
                                        "message"  : "File type not allowed"}';
                }
            }
            else
            {
                echo '{ "result" : "false",
                                        "message"  : "The image is too large for upload"}';
            }
        }

    }

 }

                my configuration file 



  define("COOKIE_LIFE", (3600 * 24 * 30));
    define("DATATABLES_RECORDS_PER_PAGE",10);
      define("SYSTEM_TEMP_DIRECTORY", "News/");
   define("DATE_DEFAULT_TIMEZONE", "Australia/Melbourne");


    / / Image uploader
define("MAX_IMAGE_UPLOAD_SIZE",10485760); // 10 MB
 define("UPLOAD_ACCEPTED_MIME_TYPES",  "image/pjpeg,image/jpeg,image/jpg,image/png,image/x-png,image/gif");
      define("UPLOAD_ACCEPTED_FILE_TYPES", "jpeg,jpg,png,gif");

   // Image Configurations
     // Categories
     define("MAIN_CATEGORY_IMAGE_PATH", "data/image/category/");
         define("MAIN_CATEGORY_IPAD_IMAGE_PATH", "data/image/category/ipad/");
            define("IMAGE_CATEGORY_MAX_UPLOAD_WIDTH",100);
      define("IMAGE_CATEGORY_MAX_UPLOAD_HEIGHT",100);
      define("IMAGE_CATEGORY_IPHONE_WIDTH",450);
        define("IMAGE_CATEGORY_IPHONE_HEIGHT",450);
       define("IMAGE_CATEGORY_IPAD_WIDTH",450);
          define("IMAGE_CATEGORY_IPAD_HEIGHT",450);

           // Products
         define("PRODUCT_IMAGE_THUMB_PATH", "data/image/product/thumb/");
       define("PRODUCT_IMAGE_GALLERY_IPHONE", "data/image/product/gallery/iphone/");
          define("PRODUCT_IMAGE_GALLERY_IPAD", "data/image/product/gallery/ipad/");
         define("PRODUCT_IMAGE_IPHONE", "data/image/product/iphone/");
         define("PRODUCT_IMAGE_IPAD", "data/image/product/ipad/");
           define("CAMPAIGN_IMAGE_PATH", "data/image/campaign/");
       define("IMAGE_PRODUCT_MAX_UPLOAD_WIDTH",100);
      define("IMAGE_PRODUCT_MAX_UPLOAD_HEIGHT",100);
         define("IMAGE_PRODUCT_IPAD_LARGE_WIDTH",400);
        define("IMAGE_PRODUCT_IPAD_LARGE_HEIGHT",400);
           define("IMAGE_PRODUCT_IPHONE_LARGE_WIDTH",190);
        define("IMAGE_PRODUCT_IPHONE_LARGE_HEIGHT",190);
          define("IMAGE_PRODUCT_THUMB_WIDTH",250);
          define("IMAGE_PRODUCT_THUMB_HEIGHT",250);
        define("IMAGE_PRODUCT_IPAD_IMG_GALARY_THUMB_WIDTH",213);
       define("IMAGE_PRODUCT_IPAD_IMG_GALARY_THUMB_HEIGHT",196);
      define("IMAGE_PRODUCT_IPHONE_IMG_GALARY_THUMB_WIDTH",90);
      define("IMAGE_PRODUCT_IPHONE_IMG_GALARY_THUMB_HEIGHT",90);
      define("IMAGE_CAMPAIGN_MAX_UPLOAD_WIDTH",100);
      define("IMAGE_CAMPAIGN_MAX_UPLOAD_HEIGHT",100);
          define("IMAGE_CAMPAIGN_THUMB_WIDTH",90);
            define("IMAGE_CAMPAIGN_THUMB_HEIGHT",90);

         define("IMAGE_CAMPAIGN_IPHONE_WIDTH",320);
         define("IMAGE_CAMPAIGN_IPHONE_HEIGHT",196);

       define("IMAGE_CAMPAIGN_IPAD_WIDTH",768);
       define("IMAGE_CAMPAIGN_IPAD_HEIGHT",578);

        //video
      define("VIDEO_IMAGE_GALLERY_IPHONE", "data/image/video/iphone/");
        define("VIDEO_IMAGE_GALLERY_IPAD", "data/image/video/ipad/");
       define("IMAGE_VIDEO_IPAD_IMG_GALARY_THUMB_WIDTH",213);
        define("IMAGE_VIDEO_IPAD_IMG_GALARY_THUMB_HEIGHT",196);
         define("IMAGE_VIDEO_IPHONE_IMG_GALARY_THUMB_WIDTH",90);
        define("IMAGE_VIDEO_IPHONE_IMG_GALARY_THUMB_HEIGHT",90);

       // Message Colors
           define("MSG_COLOR_SUCCESS", "#3C7B11");
           define("MSG_COLOR_FAILED", "#FF8000");
       define("MSG_COLOR_ERROR", "#F00");

    // SQL
       define("SQL_DATE_PATTERN", "yyyy-MM-dd HH:mm:ss");

     // Customer
      define("CUSTOMER_ENCRYPTION_KEY", "ENGETTD@@33");
        define("CUSTOMER_IMAGE_THUMB_PATH", "data/image/profile/");
      define("IMAGE_CUSTOMER_MAX_UPLOAD_WIDTH",0);
      define("IMAGE_CUSTOMER_MAX_UPLOAD_HEIGHT",0);
     define("IMAGE_CUSTOMER_THUMB_WIDTH",125);
      define("IMAGE_CUSTOMER_THUMB_HEIGHT",125);

     // Push Notification
        define("APN_HOST","ssl://gateway.push.apple.com");
         define("APN_PORT","2195");
      define("APN_CERTIFICATE_FILE","ck.pem");

1 个答案:

答案 0 :(得分:2)

您的代码中似乎定义了一个常量“MAX_IMAGE_UPLOAD_SIZE”。如果img大小超过了它,它回声“......文件太大了”。

您只需在代码中找到定义MAX_IMAGE_UPLOAD_SIZE的位置。它可能在一些附带的配置文件中,或者您上面摘录的脚本包含(或要求)的其他文件。