我的项目实际上涉及2个页面。第1页是一个表单,用于将上传的图像提交到第2页action="2page.php"
并将显示和预览图像。它应该在客户端服务器上运行,这意味着不涉及将图像文件保存到其中并将特定图像检索回我想要执行的页面的数据库。实际上我已经写了PHP
像这样的脚本:<?php echo $_GET[image]; ?>
在第二页显示上传的图像,但它不起作用。
如果您的目标是上传图像并将其存储在服务器上的目录中,那么此代码示例可能会帮助您入门(尽管我不会发誓它没有错误或安全)。它是一个用于上传、保存和显示图像的单页表单。
<?php
// prevent timezone warnings
date_default_timezone_set('America/New_York');
// set the upload location
$UPLOADDIR = "images/";
// if the form has been submitted then save and display the image(s)
if(isset($_POST['Submit'])){
// loop through the uploaded files
foreach ($_FILES as $key => $value){
$image_tmp = $value['tmp_name'];
$image = $value['name'];
$image_file = "{$UPLOADDIR}{$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{
?>
<form name='newad' method='post' enctype='multipart/form-data' action=''>
<table>
<tr>
<td><input type='file' name='image'></td>
</tr>
<tr>
<td><input name='Submit' type='submit' value='Upload image'></td>
</tr>
</table>
</form>
<?php
}
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)