多个图片上传无法正常工作 [英] Multiple image upload not working properly

查看:106
本文介绍了多个图片上传无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个照片分享博客,注册用户上传图片。

I have a photo-sharing blog where registered users upload images. The images then go to the Admin Panel where I review them and they get published after my approval.

我要启用多个图片上传,即用户必须能够选择并上传多个图片。

I want to enable multiple image upload i.e. the users must be able to select and upload multiple images.

我已尝试在代码中加入多个属性。它已启用多个图片的选择和上传,但只有一个图片显示在我的管理控制台中以供审核,所有其他图片都会被舍弃。

I have tried putting the multiple attribute in the code. It has enabled the multiple images to be selected and uploaded BUT only one image is showing up in my Admin Panel for approval and all other images are discarded. How can I fix that?

这是上传页面的代码:

<?php include ('header.php');?>

<?php @session_start();?>

<div class="domainSearchComplex">
<img src="theme_image/banner-mega.jpg" title="Change Image" style="width:960px; height:280px; margin-left:-55px !important;border-radius:15px;"> </div>

<?php //include ('slider.php');
$username = $_SESSION['user'];
$type = $_SESSION['type']; 
$id_no = $_SESSION['id_no'];
if(isset($_POST['insert']))
{
$pic = $_FILES["image"]["name"];
$today = date('Y-m-d H:i:s');
if ($_FILES["image"]["error"] > 0)
{ $msg= "Error........Code: " . $_FILES["image"]["error"]; }
else
{
$pic = uniqid().$_FILES["image"]["name"];
move_uploaded_file($_FILES["image"]["tmp_name"],
"posts_images/" . $pic);


$query ="insert into `all_images` (`id_no`,`user_name`,`image`,`status`,`date`) values ('$id_no','$username' ,'$pic','9','$today')";

if(mysql_query($query))      
            {                   
                $msg = "<span style=\"color: green;margin-left:25px;margin-top:25px;\">Image Inserted Successfully...!</span>";
                }
        else        
        {$msg = "Error in insertion.........".mysql_error();    }
}}  
?>

<div style="height: 0;" class="clear">&nbsp;</div>
<div class="clearfix" id="mainContent">

<div class="clearfix" id="homeFeatured">

<?php include ('sidebar.php');?>

<div style="width: 66%; float: left;">
<h1 style="color:#DD003D; margin:39px 25px 17px 193px;">Post Your Images</h1>
<div class="tdp48 signupPart">

<div class="signUp" style="width:603px !important; height:400px !important; margin:0px 11px 17px 11px  !important; border-radius: 8px;">

<?php 
$qryc = "SELECT * FROM `register` where id_no='$id_no'";
$resc = mysql_query($qryc);
$rpc = mysql_fetch_array($resc);
$image = $rpc['image'];
?>

<form class="form2" enctype="multipart/form-data"  onsubmit="return validate();" method="post">
   <div class="loginTag" style="margin-top:-14px !important"><center>
    <br /><?php echo @$msg;?>

    <table style="margin-top:70px;">
        <tr>
            <td class="firstTd"><label>Image:</label></td>
            <td class="secondTd"><input name="image" multiple="" id="image" type="file" value="" /></td>
        </tr>

        <tr><td colspan="2" align="center"><input type="submit" value="INSERT" name="insert" class="btnSignup"  /></td></tr>
    </table>
</div>
</form>
</ul>
<!--</div>-->
</div> </div> </div> </div> </div>

<?php include ('footer.php');?>

<style>.menu2 {margin-top:4px !important;}
</style>
<script type="text/javascript">

function validate () {

var image = document.getElementById('image').value; 

if (image == '') {

    alert ('Please enter your image');
    return false;
    }

}
</script>


推荐答案

看起来你有一个很大的SQL注入问题你应该先修复。

Looks like you have a pretty big SQL injection problem here that you should fix first.

使用PDO与参数绑定 - 不要直接在sql语句内引用变量

Use PDO with parameter binding - don't quote variables directly inside your sql statement

,它看起来不像你循环或做任何事情在代码中添加多个图像?

As for multiple images, it doesn't look like you're looping or doing anything to add multiple images in your code?

我会期望看到

foreach($images as $image){
  //insert image here
}

这篇关于多个图片上传无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆