请一些人可以帮助我,我是新的php我试图显示存储在一个名为uploads的文件夹中的图像,所有的图像路径都存储在我调用的一个字段中,文件 这是表单代码
<form enctype="multipart/form-data" action="" method="post">
<table width="800" align="center">
<tr>
<td> <h1>Insert new post</h1> </td>
</tr>
<tr>
<td>Post Title:</td>
<td><input type="text" name="post_title" /></td>
</tr>
<tr>
<td>Post Image:</td>
<td>
<input name="file[]" type="file" id="file"/>
<input type="button" id="add_more" class="upload" value="Add More Files"/>
</td>
</tr>
<tr>
<td>Post Content:</td>
<td><textarea name="post_content" rows="16" cols="30"> </textarea></td>
</tr>
<tr>
<?php
if (isset($_POST['submit'])) {
$errors= array();
$j = 0;
$target_path = "uploads/";
for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
$validextensions = array("jpeg", "jpg", "png" , "gif");
$ext = explode('.', basename($_FILES['file']['name'][$i]));
$file_extension = end($ext); // Store extensions in the variable.
$target_path = $target_path. md5(uniqid()) . "." . $ext[count($ext) - 1] ;
$j = $j + 1;
if (($_FILES["file"]["size"][$i] < 100000)
&& in_array($file_extension, $validextensions)) {
if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {
$file_name_all.=$target_path."*";
$filepath = rtrim($file_name_all.'');
$post_title = $_POST['post_title'];
$post_content = $_POST['post_content'];
if($post_title=='') {
echo "<script>alert('please fill all feilds') </script>" ;
exit();
}
else {
$insert_posts = "insert into posts (post_title,file,post_content) values ( '$post_title','$target_path','$post_content')";
$run_posts = mysql_query($insert_posts);
echo"<script>alert('post has been published!')</script>";
}
}
?>
,这是预览代码
<?php
if(!isset($_GET['cat'])) {
$get_posts = "select *from posts limit 0,5 ";
$run_posts = mysql_query($get_posts);
while ($row_posts = mysql_fetch_array($run_posts))
$post_id = $row_posts['post_id'];
$post_title = $row_posts['post_title'];
$file = $row_posts['file'];
$post_content =substr($row_posts['post_content'],0,200);
echo"
<li>
<h3><a id=1title' href='details.php?post=$post_id'>$post_title</a></h3>
<img src='uploads/$file' width='250' height='150'/>
</p>
$post_content
<div >
</div><br/>
</li>
";
?>
以下是我上传到数据库的两张图片的路径,我的目的是显示这些图片
上传/ c1d225856af139c794b5358e61e99cd3.jpg1935ecdda8ed0c5602286a5398959931.jpg