各ユーザーが独自の画像を表示するためのこのコードがあります。時間を節約するためにコメントします
<?php
session_start();
$name=$_SESSION['valid_user']; //saved current username in variable
$loc="./uploads/"; //location of image directory
$path=$loc.$name; //current user's folder to save his images
echo $path."<br>"; //i used this to make sure the path is ok, only for testing
if(is_dir($path)) //if directory exists, show it exists,otherwise show it
{ //doesnt exists
echo "<br>exists";
}
else
{
echo "<br>not exists";
}
$files = glob($path."/");
for ($i=1; $i<count($files); $i++)
{
$num = $files[$i]; //picture number
print $num."<br />";
echo '<img src="'.$path.'" alt="random image" height="100" width="100"/>'."<br /><br />";
} //shows the picture till the last one
?>
私が得る出力はこれです
./uploads/user_name
exists
フォルダーが空でなくても、画像は表示されません(アップロードスクリプトは正常に機能します)。
編集; 解決しました(担当者が少なく、自分の質問に答えられません)。
とった。気にする人は、この行をここに
echo '<img src="' . $path . '/' . $files[$i] . '" <!-- etc --> />';
すでにパスが含まれている $files を追加したため、機能していませんでした。
/uploads/username/uploads/username
それは2回同じパスでした.$pathを削除して、
<img src="' . $files[$i] . '"
トリックをしました。ご協力ありがとうございました。