PHP:image-won';t显示

PHP:image-won';t显示,php,image,Php,Image,我有一个表单可以将数据上传到DB,其中包括上传图像的目录路径。一切正常,除了图像无法显示 在我的浏览器中查看源代码会告诉我该图像已找到,但我会不断得到损坏的图像图标 这是我的密码: $dir = "../uploaded_images/"; $filePath = $row['images_path']; $fileArray = explode("*", $filePath); if (count($fileArray) > 0) { $image = $fileArray[0

我有一个表单可以将数据上传到DB,其中包括上传图像的目录路径。一切正常,除了图像无法显示

在我的浏览器中查看源代码会告诉我该图像已找到,但我会不断得到损坏的图像图标

这是我的密码:

$dir = "../uploaded_images/";

$filePath = $row['images_path'];
$fileArray = explode("*", $filePath);

if (count($fileArray) > 0) {
   $image = $fileArray[0];
   echo "<img src='$image' width='300px'>";
}
$dir=“../upload_images/”;
$filePath=$row['images_path'];
$fileArray=分解(“*”,$filePath);
如果(计数($fileArray)>0){
$image=$fileArray[0];
回声“;
}
在表单中,您可以上载多个文件。在DB中,这些文件会得到一个随机前缀,然后是文件名,比如3456456745654_imageName.jpg

如果上传了多个文件,它们会用星号(*)分割,这就是我爆炸的原因

然后,为了只打印一个图像,我检查与特定记录相关的图像数量,然后只显示第一个

PS.此代码用于显示与选定图像相关的所有图像:

$dir = "uploaded_images/";

$filePath = $row['images_path'];
$fileArray = explode("*", $filePath);

foreach ($fileArray as $file) {
   if (file_exists($dir . $file)) {
      echo "<img class='images' src='$dir/$file' width='300px;'>";
   }
}
$dir=“上传的图片/”;
$filePath=$row['images_path'];
$fileArray=分解(“*”,$filePath);
foreach($fileArray作为$file){
如果(文件_存在($dir.$file)){
回声“;
}
}
但这是用于显示所选车辆信息(包括所有图像)的不同页面


我只需要在登录页面上显示每辆车的一张图像,该页面列出所有车辆。

必须使用目录:

$dir = "../uploaded_images/";

$filePath = $row['images_path'];
$fileArray = explode("*", $filePath);

if (count($fileArray) > 0) {
   $image = $fileArray[0];
   if (file_exists($dir . $image)) {
      echo "<img class='images' src='$dir/$image' width='300px;'>";
   }
 }
$dir=“../upload_images/”;
$filePath=$row['images_path'];
$fileArray=分解(“*”,$filePath);
如果(计数($fileArray)>0){
$image=$fileArray[0];
如果(文件_存在($dir.$image)){
回声“;
}
}

必须使用目录:

$dir = "../uploaded_images/";

$filePath = $row['images_path'];
$fileArray = explode("*", $filePath);

if (count($fileArray) > 0) {
   $image = $fileArray[0];
   if (file_exists($dir . $image)) {
      echo "<img class='images' src='$dir/$image' width='300px;'>";
   }
 }
$dir=“../upload_images/”;
$filePath=$row['images_path'];
$fileArray=分解(“*”,$filePath);
如果(计数($fileArray)>0){
$image=$fileArray[0];
如果(文件_存在($dir.$image)){
回声“;
}
}

是$image=$fileArray[0];获取图像的完整路径?为什么编写不同的代码?在第一个示例中,您根本不使用$dir。您是否使用asterix(*)作为路径分隔符?如果我要猜测,我会说您需要将路径根指向网站的文档根。@Bonner是的。它是一个路径分隔符,即$image=$fileArray[0];获取图像的完整路径?为什么编写不同的代码?在第一个示例中,您根本不使用$dir。您是否使用asterix(*)作为路径分隔符?如果我要猜测,我会说您需要将路径根指向网站的文档根。@Bonner是的。这是一个路径分隔器