我正在用php创建一个动态站点,在其中从后端添加了图库图像。上传的图像将转到“上传”文件夹。但是我无法在主页上显示它。
这是我用于从后端添加图像的代码
<?php
require_once("config/connection.php");
$imgtitle="";
//$discription="";
$file_ext="";
$file_name="";
if(isset($_POST['btnadd']))
{
$proname=$_POST['titlename'];
$file_name = $_FILES['txtfile']['name'];
$file_size =$_FILES['txtfile']['size'];
$file_tmp =$_FILES['txtfile']['tmp_name'];
$file_type=$_FILES['txtfile']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['txtfile']['name'])));
$imagename=date("d-m-Y")."-".time().".".$file_ext;
$expensions= array("jpeg","jpg","png","gif");
if(in_array($file_ext,$expensions)=== false){
echo "extension not allowed, please choose a JPEG or PNG or GIF file.";
}
else if($file_size > 2097152){
echo 'File size must be excately 2 MB';
}
else if(empty($errors)==true){
$rand_name = md5(time());
$rand_name= rand(0,999999999);
$source=$_FILES['txtfile']['tmp_name'];
$destination="../uploads/".$imagename;
move_uploaded_file($source,$destination);
}
else{
print_r($errors);
}
$query1="insert into products_tb(proimg,proname)values('{$destination}','{$proname}')";
$result=mysql_query($query1,$connection) or die(mysql_error()) ;
if($result>0)
{
echo "<p style='color:green'>Image added Successfully</p>";
}
}
?>
<form action="" name="" class=" form-group" method="post" enctype="multipart/form-data">
<table class="">
<tr>
<td><label for="name">Name</label></td>
<td><input type="text" class="form-control" name="titlename" id="titlename" required placeholder="Please enter Title Name"></td>
</tr>
<tr>
<td><label for="img_upload">Image Upload</label></td>
<td>
<input type="file" name="txtfile" id="txtfile" required/>
<!--<input type="file" name="image" id="image"/>
--> </td>
</tr>
<tr>
<td></td>
<td>
<input name="btnadd" id="btnadd" class=" btn btn-primary" type="submit" value="Submit">
</td>
</tr>
</table>
</form>
<div style="background-color:#e9ca76" class="gallery-w3layouts" id="portfolio">
<div class="container-fluid">
<h5 style="font-family: 'Crafty Girls';" class="title-w3">Gallery</h5>
<div class="fancybox" align="center">
<?php
require_once("admin/config/connection.php");
;
$proname="";
$query1="select * from products_tb";
$resource1=mysql_query($query1,$connection);
$result1="";
$id="";
while($record=mysql_fetch_array($resource1))
{
$pid=$record['pid'];
$img="uploads/".$record['proimg'];
$proname=$record['proname'];
//$proitems=$record['proitem'];
$result1.="<div class='col-md-4 col-sm-4 mrgn_less prd'>
<img class='fancybox' src='$img' '><br>
</div>";
}
?>
<div class="carousel-inner ">
<div class="item active">
<div class="container-fluid mrgn_less">
<div class="row">
<div class="col-md-12 mrgn_less col_bg ">
<?php echo $result1;?>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>