php---使用php获取目录中的图像路径,并使用HTML显示图像

php---使用php获取目录中的图像路径,并使用HTML显示图像,php,Php,我有一个显示图像的目录: www\item(directory) 1.gif 如何使用PHP获取图像路径 我还想检查目录是否存在,我得到的图像路径,如果不显示错误 如果获得图像路径,我希望使用HTML显示图像,如: <img src="(image path)" style="width:304px;height:228px"> 假设将映像路径放入变量>$image\u path 只要这样做 <img src="<?php echo $image_path; ?>

我有一个显示图像的目录:

www\item(directory)
1.gif
如何使用PHP获取图像路径

我还想检查目录是否存在,我得到的图像路径,如果不显示错误

如果获得图像路径,我希望使用HTML显示图像,如:

<img src="(image path)" style="width:304px;height:228px">

假设将映像路径放入变量>$image\u path

只要这样做

<img src="<?php echo $image_path; ?>" style="width:304px;height:228px">
style=“宽度:304px;高度:228px“>


亲爱的雷克斯,做这个


您需要提供更多信息。您上面的目录格式不正确,因此我不知道您在这里想要什么。拼写检查您的问题也无济于事。欢迎使用so.:p目录路径位于(www\item)如何使用php获取图像路径?@Rex-您需要获取的所有内容都必须有一个源。图像位于www\item中,我需要使用php查找它。因为我想检查目录是否存在
if(is_dir('www/item')){}
<?php 
$file = "C:\myfile.jpg";
if(file_exists($file)){
        if(is_readable($file)){
        echo '<img src="'.$file.'">';
        }
    }
    else
    {
    // UNABLE TO FIND FILE;
    }
?>
<?php
$path = "www/item";
$folder = opendir($path);
$pic = false;
while(false !== ($file = readdir($folder))){
    $fileName = $path.$file;
    $info = pathinfo($path.$file);
    $ext = strtolower($info['extension']);
    $allowed =array("jpg","bmp","png","gif");
    if(filetype($fileName) == "file"){
        if(in_array($ext,$allowed)){
            echo"
            <div style='display:inline-block'>
            <img src='$fileName' style='width:96px;height:70px;' title='Filename: $file'>
            <a target = '_blank' href='$fileName'>Download</a>
            </div>
            ";
            $pic = true;
            }
        }
    }
if($pic == false){
    echo "There are no images in $path";
    }
?>