php图像上传和显示在同一个div中
我想上传一个图像到一个目录,我想在一个div中同时显示它。这是我的html页面的一部分php图像上传和显示在同一个div中,php,Php,我想上传一个图像到一个目录,我想在一个div中同时显示它。这是我的html页面的一部分 <body> <div id="imgspace1" class="container"> <form action="php/imgUpload.php" method="POST" enctype="multipart/form-data"> <input type="file" name="fileToUpload" id="fileToUploa
<body>
<div id="imgspace1" class="container">
<form action="php/imgUpload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload" name="Submit">
</form>
</div>
这是我的php页面
<?php
// set the upload location
$imgUpload = "../uploads/";
// if the form has been submitted then save and display the image(s)
if(isset($_POST['Submit'])){
// loop through the uploaded file
foreach ($_FILES as $key => $value){
$image_tmp = $value['tmp_name'];
$image = $value['name'];
$image_file = "{$imgUpload}{$image}";
// move the file to the permanent location
if(move_uploaded_file($image_tmp,$image_file)){
echo <<<HEREDOC
<div style="float:left;margin-right:10px">
<img src="{$image_file}" alt="file not found" /></br>
</div>
HEREDOC;
}
else{
echo "<h1>image file upload failed, image too big after compression</h1>";
}
}
}
else{
?>
<?php
}
?>
但图像显示在另一页中。那么我如何在“imgspace1”分区中显示上传的图像呢 此示例演示了问题的解决方案
使用PLUpload图像/文件上传器。它在后端上传文件,您可以使用path显示,您是使用AJAX发布表单还是使用简单的HTTP post请求?在另一个可以看到图像的页面上,您是否使用外部URL?谢谢你,Chintan7027。我会试试的。我认为如果我使用ajax会更好,对吗?