简体   繁体   中英

Image File on PHP doesn't display my uploaded image

if (isset($_POST['submit2'])){

$file_name = $_FILES['file']['name'];
$file_type = $_FILES['file']['type'];
$file_size = $_FILES['file']['size'];
$file_tem_loc = $_FILES['file']['tmp_name'];
$file_store = "function/upload/".$file_name;

$AAnimalName = mysqli_real_escape_string($conn, $_POST['Aanimal']);
$Abreed = mysqli_real_escape_string($conn, $_POST['Abreed']);
$Asex = mysqli_real_escape_string($conn, $_POST['Asex']);
$Acolor = mysqli_real_escape_string($conn, $_POST['Acolor']);
$Amark = mysqli_real_escape_string($conn, $_POST['Amark']);
$file_name = mysqli_real_escape_string($conn, $_FILES['file']['name']);


$sql = "INSERT INTO adoption (AAnimalName, Abreed, Asex, Acolor, Amark, image)
 VALUES ('$AAnimalName', '$Abreed', '$Asex', '$Acolor', '$Amark', '$file_name')";
$result = mysqli_query($conn,$sql);


if(move_uploaded_file($file_tem_loc, $file_store)){
    echo "";



 $folder = "function/upload/";

    if (is_dir($folder)){
        if ($handle = opendir($folder))
        {
            while (($file = readdir($handle)) !=false)
             {
                if ($file == '.' || $file = '..') continue;
                echo '<img src = "function/upload/'.$file.'" width = "250" height="250">';
            }
            closedir($handle);
        }
    }
 }

As seen in my code. The image upload is successful and stores exactly at "function/upload/" code on my display doesn't work. What i understand from the code that i have on the display part, I'm just trying to open a dir. Help anyone?

Uploaded images display part of code is not working because of this line

Your code

if ($file == '.' || $file = '..') continue;

You miss one = symbol.

Fixed code

if ($file == '.' || $file == '..') continue;

Your code always uses a function "continue" and skips all results. That is the reason you don't see any images.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM