【发布时间】:2016-09-14 09:43:40
【问题描述】:
我有一点问题。我在我的系统上放置了一张个人资料图片,其中图片存储在一个文件中,我从数据库中调用它。我想要发生的是这样的:
对于尚未上传照片的人,我希望系统打开某个目录作为默认头像。所以,我的代码是这样的:如果有上传的图片,它会检查文件,如果没有,它会打开一个特定的目录。
<?php
$profquery = "select User_ID from tusers where vName ='".$_SESSION['SESS_vName_JO'] ."' ";
$search = mysql_query($profquery);
$row=mysql_fetch_assoc($search);
$q=$row['User_ID'];
$dir= "../../profpic/" . $q . "/";
$profimge=(count(glob($dir)) === 0) ? 'Empty' : 'Not empty';
if(profimge=="Empty"){
$pimge = opendir($profimge);
$files = array();
while ($pfiles[] = readdir($pimge));
natsort($pfiles);
closedir($pimge);
foreach ($pfiles as $pfile)
{
if ($pfile == "." || $pfile == ".." || $pfile == "thumbs.db" || $pfile == "Thumbs.db" || $pfile == "")
{
//skip
}else
{
$profImage = "../../profpic/" . $profpic . "/" . $pfile;
$pathofimage = "../../profpic/" . $profpic . "/";
}
}
}else if($profimge=="Not empty"){
$folder = 0;
$default = "../../profpic/". $folder. "/";
$pimge = opendir($default);
$files = array();
while ($pfiles[] = readdir($pimge));
natsort($pfiles);
closedir($pimge);
foreach ($pfiles as $pfile)
{
if ($pfile == "." || $pfile == ".." || $pfile == "thumbs.db" || $pfile == "Thumbs.db" || $pfile == "")
{
//skip
}else
{
$profImage = "../../profpic/" . $profpic . "/" . $pfile;
$pathofimage = "../../profpic/" . $profpic . "/";
}
}
}
?>
我的第一个代码是这样的,它也不起作用。
<?php
$profquery = "select User_ID from tusers where vName ='".$_SESSION['SESS_vName_JO'] ."' ";
$search = mysql_query($profquery);
$row=mysql_fetch_assoc($search);
$profpic=$row['User_ID'];
$cntImage=0;
$cStatus="";
$FName=$profpic;
$profimge= "../../profpic/" . $profpic . "/";
if(file_exists($profimge)){
$pimge = opendir($profimge);
$files = array();
while ($pfiles[] = readdir($pimge));
natsort($pfiles);
closedir($pimge);
foreach ($pfiles as $pfile)
{
if ($pfile == "." || $pfile == ".." || $pfile == "thumbs.db" || $pfile == "Thumbs.db" || $pfile == "")
{
//skip
}else
{
$profImage = "../../profpic/" . $profpic . "/" . $pfile;
$pathofimage = "../../profpic/" . $profpic . "/";
}
}
}else{
$folder = 0;
$default = "../../profpic/". $folder. "/";
$pimge = opendir($default);
$files = array();
while ($pfiles[] = readdir($pimge));
natsort($pfiles);
closedir($pimge);
foreach ($pfiles as $pfile)
{
if ($pfile == "." || $pfile == ".." || $pfile == "thumbs.db" || $pfile == "Thumbs.db" || $pfile == "")
{
//skip
}else
{
$profImage = "../../profpic/" . $profpic . "/" . $pfile;
$pathofimage = "../../profpic/" . $profpic . "/";
}
}
}
?>
【问题讨论】:
-
你试过什么?
-
向我们展示您尝试过的代码。
-
不让我发布我的代码..