是這樣的,
弟在目錄裡多放了一個使用者相片的目錄,
但是, 並不是每一位使用者都願意上傳相片進來,
所以~
有沒有辨法有一個判斷方式是,
當使用者有上傳JPG相片時, 就秀使用者相片,
而當使用者未上傳相片時就預設一張相片,
對了~ 這個功能並不是 "頭像預設"
而是弟在個人資料內另開的一個圖檔連結,
假設使用者名稱是 "ABC", 那麼就會將ABC.JPG秀在個人資料內!!
PS, 由於弟的站是在公司的Intranet上, 所以沒辨法公布!!
[問題]如何判斷圖檔是否存在?? [已解決]
版主: 版主管理群
[問題]如何判斷圖檔是否存在?? [已解決]
最後由 超級牛 於 2004-02-04 13:33 編輯,總共編輯了 2 次。
-
GeniusKiKi
- 竹貓忠實會員

- 文章: 1086
- 註冊時間: 2003-10-28 14:50
我剛試了這個語法,bu 寫:try...
您看看是不是您要的... ^^"
在 profile.php 的最下方加了
// Cho 判斷使用者圖檔是否存在\r
$username=userdata['username'];
$userimg1='../Pictures/UserPics/' . $username . '.jpg';
$userimg2='../Pictures/UserPics/no-image.gif';
if (file_exists($userimg1)) {
$user-img = $userimg1;
} else {
$user-img = $userimg2;
}
然後再將 profile_view_body.tpl 內的使用者相片改成
<img src="{USER-IMG}" border="0" alt="{USERNAME}" onload="javascript:if(this.width>screen.width-350) this.width=screen.width-350">
可是, 一開使用者的內容時就跑出,
Parse error: parse error, unexpected '[' in c:\appserv\pwc\profile.php on line 133
就是 $username=userdata['username']; 這一行就有問題??
這又是那有問題??
Thanks..GeniusKiKi 寫:http://phpbb-tw.net/phpbb/viewtopic.php?t=21737
參考看看這篇文章
然後每個用戶開一個資料夾給他(木亥火暴)
裡面都丟一個這樣的檔案
這樣也許會簡單許多
我會試者做做看!!
嗯~ 原則上我在中午1:30左右就找到了少掉了的"$"... (但是下面還是會有錯)bu 寫:$username=$userdata['username'];
^^" 才對...
所以又將 "=" 改成了 "==" 才可以執行.
目前的程式是這樣的..
// Cho 判斷使用者圖檔是否存在\r
$username=$userdata['username'];
$userimg1='../Pictures/UserPics/' . $username . '.jpg';
$userimg2='../Pictures/UserPics/no-image.gif';
if (file_exists($userimg1)) {
$user-img == $userimg1;
} else {
$user-img == $userimg2;
}
$template->assign_vars(array('user-img' => $userimg1,));
$template->pparse('view_body');
// Cho 判斷使用者圖檔是否存在\r
在最後面兩行, 我試圖將user-img回給profile_view_body,
但是在profile_view_body內加入的{user-img}內卻抓不到這個變數..
這... 又是那兒做錯了??
弄了幾天, 終於搞定了!!
原來.. 一開始就弄錯了檔案..
關鍵在於 \includes\usercp_viewprofile.php
祗要加入判斷式
$username=$profiledata['username'];
$checkimg="./Pictures/UserPict/" . $username . ".jpg";
$no_image="./Pictures/UserPict/no-image.gif";
if (file_exists($checkimg))
{$user_img = $checkimg;}
else
{$user_img = $no_image;}
然後再將 $user_img 回給 profile_view_body 就大功告成囉!!
'USER_IMG' => $user_img,
原來.. 一開始就弄錯了檔案..
關鍵在於 \includes\usercp_viewprofile.php
祗要加入判斷式
$username=$profiledata['username'];
$checkimg="./Pictures/UserPict/" . $username . ".jpg";
$no_image="./Pictures/UserPict/no-image.gif";
if (file_exists($checkimg))
{$user_img = $checkimg;}
else
{$user_img = $no_image;}
然後再將 $user_img 回給 profile_view_body 就大功告成囉!!
'USER_IMG' => $user_img,


