2012-04-05 55 views
-2

我真的搜索了所有的網站,並試圖使用GD getimagesize功能,但沒有希望 請我想設置最小和最大的圖像寬度和高度上傳..如果不等於然後顯示錯誤; 這裏是原代碼:定義上傳圖像的最大和最小寬度的高度

<?php 
$page = "user_editprofile_photo"; 
include "header.php"; 
$task = (isset($_POST['task']) ? $_POST['task'] : NULL); 
// CHECK FOR ADMIN ALLOWANCE OF PHOTO 
if(!$user->level_info['level_photo_allow']) 
{ 
    header("Location: user_home.php"); 
    exit(); 
} 
// SET ERROR VARIABLES 
$is_error = 0; 
// DELETE PHOTO 
if($task == "remove") 
{ 
    $user->user_photo_delete(); 
    $user->user_lastupdate(); 
    exit(); 
} 
// UPLOAD PHOTO 
if($task == "upload") 
{ 
    $user->user_photo_upload("photo"); 
    $is_error = $user->is_error; 
    if(!$is_error) 
    { 
    // SAVE LAST UPDATE DATE 
    $user->user_lastupdate(); 
    // DETERMINE SIZE OF THUMBNAIL TO SHOW IN ACTION 
    $photo_width = $misc->photo_size($user->user_photo(), "100", "100", "w"); 
    $photo_height = $misc->photo_size($user->user_photo(), "100", "100", "h"); 

    // INSERT ACTION 
    $action_media = Array(Array('media_link'=>$url->url_create('profile', $user->user_info['user_username']), 'media_path'=>$user->user_photo(), 'media_width'=>$photo_width, 'media_height'=>$photo_height)); 
    $actions->actions_add($user, "editphoto", Array($user->user_info['user_username'], $user->user_displayname), $action_media, 999999999, TRUE, "user", $user->user_info['user_id'], $user->user_info['user_privacy']); 
    } 
} 

// GET TABS TO DISPLAY ON TOP MENU 
$field = new se_field("profile", $user->profile_info); 
$field->cat_list(0, 0, 0, "profilecat_id='{$user->user_info['user_profilecat_id']}'"); 
$cat_array = $field->subcats; 


// ASSIGN VARIABLES AND INCLUDE FOOTER 
$smarty->assign('is_error', $is_error); 
$smarty->assign('cats', $cat_array); 
include "footer.php"; 
?> 

這裏我補充一下:

if($task == "upload") 
$photo=$user->user_photo(); 
{ 
list($img_width, $img_height, $img_type, $attrs)=getimagesize($photo); 
    if($img_width >= 193 && $img_height >= 290) 
    $user->user_photo_upload("photo"); 
    $is_error = $user->is_error; 
    if(!$is_error) 

1這樣:

if($task == "upload")$photo = $user->user_photo(); 
    { $user->user_photo_upload("photo"); 

沒有圖像會不惜一切.....

上傳

2-以這種方式:

if($task == "upload"){ 
$user->user_photo_upload("photo"); 
$photo = $user->user_photo(); 

沒有效果,它甚至可以上傳16像素的圖像。 謝謝 如果你能幫忙,我會很感激。

+2

您可以嘗試格式化該代碼,以幫助我們幫助您! – gosukiwi 2012-04-05 17:38:25

+0

我試了,但編輯..總是給我錯誤不符合我們的規則。 – Sanshiro 2012-04-05 17:43:44

回答

2

它看起來像你的if($task == "upload")是不完全包括你想要它。如果你多一點人類可讀的格式看代碼:

<?php 
$task = (isset($_POST['task']) ? $_POST['task'] : NULL); 
$is_error = 0; 
if($task == "remove") 
{ 
    $user->user_photo_delete(); 
    $user->user_lastupdate(); 
    exit(); 

} 
if($task == "upload") $photo = $user->user_photo(); 
{ 
    list($img_width, $img_height, $img_type, $attrs) = getimagesize($photo); 
    if($img_width >= 193 && $img_height >= 290) $user->user_photo_upload("photo"); 
    $is_error = $user->is_error; 
    if(!$is_error) 
    { 
     $user->user_lastupdate(); 
     $photo_width = $misc->photo_size($user->user_photo(), "100", "100", "w"); 
     $photo_height = $misc->photo_size($user->user_photo(), "100", "100", "h"); 
     $action_media = array(array('media_link' => $url->url_create('profile', $user->user_info['user_username']), 'media_path' => $user->user_photo(), 'media_width' => $photo_width, 'media_height' => $photo_height)); 
     $actions->actions_add($user, "editphoto", array($user->user_info['user_username'], $user->user_displayname), $action_media, 999999999, TRUE, "user", $user->user_info['user_id'], $user->user_info['user_privacy']); 

    } 

} 
$field = new se_field("profile", $user->profile_info); 
$field->cat_list(0, 0, 0, "profilecat_id='{$user->user_info['user_profilecat_id']}'"); 
$cat_array = $field->subcats; 
$smarty->assign('is_error', $is_error); 
$smarty->assign('cats', $cat_array); 
include "footer.php"; 
?> 

你可以看到$photo = $user->user_photo();也許應該去,而不是花括號。它總是要執行每次從list()開始的代碼。

我不知道這是否是問題,但您似乎有正確的想法。我不知道是什麼$photo = $user->user_photo();回報,但該文件存儲在$_FILES['image']['tmp_name'](如果您的輸入名稱有鍵入文件名和圖像),你可以得到getimagesize($_FILES['image']['tmp_name'])文件大小信息上http://www.php.net/manual/en/function.move-uploaded-file.php

的記錄請確保您的表單標籤其中有enctype="multipart/form-data"$_FILES數組將爲空。

相關問題