2012-06-05 57 views
1

我正在使用uploadify上傳圖片。有沒有什麼辦法可以限制用戶上傳圖片的寬度:670px height:200px。 這裏是我的uploadify.php代碼在uploadify中限制圖片上傳

<?php 
require_once("includes/connection.php"); 

$targetFolder = '/workbench/sudeepc/photogallery/uploads' ; 

if (!empty($_FILES)) { 
    $tempFile = $_FILES['Filedata']['tmp_name']; 
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; 
    $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name']; 

    // Validate the file type 
    $fileTypes = array('jpg','jpeg','gif','png'); // File extensions 
    $fileParts = pathinfo($_FILES['Filedata']['name']); 

    if (in_array($fileParts['extension'],$fileTypes)) { 
     move_uploaded_file($tempFile,$targetFile); 

$query="INSERT INTO `photo` (`id` , `path` , `uname`) 
VALUES (
'','${targetFile}', 'testnn');"; 
mysql_query($query,$connection); 


    } else { 
     echo 'Invalid file type.'; 
    } 
} 
?> 

在此先感謝。

回答

1

有沒有辦法,你可以限制實際上傳 - 文件將不得不爲了上傳您的服務器端邏輯來測試它的有效性 - 文件擴展名,尺寸,等...

有內置的PHP函數來確定圖像尺寸 - http://php.net/manual/en/function.getimagesize.php

getimagesize() 

的和getimagesize()函數將確定任何給定的圖像 文件的大小和文件類型和一起返回尺寸在普通HTML IMG標記內使用的高度/寬度文本字符串,以及對應的HTTP內容類型。
...
返回一個包含7個元素的數組。
索引0和1分別包含圖像的寬度和高度。

檢查文件擴展名後,您可以在圖像上調用此函數並根據您的要求測試它的尺寸。

下面是函數的輸出例 -

Array ( 
    [0] => 84 // width 
    [1] => 52 // height 
    ... 
)