我有一些代码可以让您将图像上传到文件,然后在上传后将其显示在页面上。唯一的问题是图像不会显示?
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
//echo $target_file;
$uploadOk = 1;
//$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 700000000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
/* Displaying Image*/
//$image=$_FILES["fileToUpload"]["name"];
// $img="uploads/".$image;
echo "<br>";
//echo'<br><img src="'.$img.'">';
//echo "<br><img src=\"upload/$img\">";
echo '<br><img src="$target_file">';
以下是我要显示图像的部分:
/* Displaying Image*/
echo "<br>";
echo '<br><img src="$target_file">';
答案 0 :(得分:1)
尝试:
Mixin.apply
或
echo '<br><img src="'.$target_file.'">';