多个图像上传PHP表单与一个输入 [英] Multiple Image Upload PHP form with one input

查看:142
本文介绍了多个图像上传PHP表单与一个输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力使这项工作相当长一段时间。但我似乎无法使其工作。我想有一个多图像上传形式只使用一个输入。



这是我的upload.php

 <?php 
include(../ include / session.php);

session_start();
$ allowedExts = array(jpeg,jpg,png,gif);
$ extension = end(explode(。,$ _FILES [upload] [name]));
$ b $ if(isset($ _ FILES ['upload'] ['tmp_name']))
{
for($ i = 0; $ i< count($ _ FILES ('$上传'] ['tmp_name']); $ i ++)
{

if(($ _FILES [upload] [name]< 90000000000000000)$ b $ ($ extension,$ allowedExts)){
if($ _FILES [upload] [error]> 0)
{
header('location :'。$ error);死;


{

if(file_exists(../ icons /\".$_ SESSION [username]。/。$ _FILES [ upload] [name]))
{
echoerror;
}
else
{
if(!is_dir(../ icons /。$ _SESSION [username]。/)){
mkdir(../ icons /。$ _SESSION [username]。/);


$ temp = explode(。,$ _ FILES [upload] [name]);
$ file = rand(1,999999999999)。 '。'.end($ temp);
$ b move_uploaded_file($ _ FILES [upload] [tmp_name],../icons/。$ _SESSION [username]。/。$ file);
}
}
}
} else {
echoyep error;
}
}
}
?>

如果我拿出

<$ p $($ i = 0; $ i< count($($))$ if $($ set $($ _ FILES ['upload'] ['tmp_name']))
{
_FILES ['upload'] ['tmp_name']); $ i ++)
{

与相应的右括号,似乎工作正常。图像上传完美。但事情是,它只允许我上传一个。

请真的需要你的专业知识。谢谢你

解决方案

不错的链接:

使用不同的基本解释来上传PHP单个文件



PHP文件使用验证上传



PHP多个文件上传验证(点击此处下载源代码)

PHP / jQuery多个文件上传与ProgressBar和验证(点击这里下载源代码)



  extract($ _ POST); 
$ error = array();
$ extension = array(jpeg,jpg,png,gif);
foreach($ _ FILES [files] [tmp_name] as $ key => $ tmp_name)
{
$ file_name = $ _ FILES [files] [ ] [$关键]
$ file_tmp = $ _ FILES [files] [tmp_name] [$ key];
$ ext = pathinfo($ file_name,PATHINFO_EXTENSION);
if(in_array($ ext,$ extension))
{
if(!file_exists(photo_gallery /\".$ txtGalleryName。/。$ file_name))
{
move_uploaded_file($ file_tmp = $ _ FILES [files] [tmp_name] [$ key],photo_gallery /\".$ txtGalleryName。/。$ file_name);
}
else
{
$ filename = basename($ file_name,$ ext);
$ newFileName = $ filename.time()。。。$ ext;
move_uploaded_file($ file_tmp = $ _ FILES [files] [tmp_name] [$ key],photo_gallery /\".$ txtGalleryName。/。$ newFileName);



{
array_push($ error,$ file_name,);


$ / code $ / pre

你必须检查你的HTML代码

 < form action =create_photo_gallery.phpmethod =postenctype =multipart / form-data> 
< table width =100%>
< tr>
< td>选择相片(一个或多个):< / td>
< td>< input type =filename =files []multiple />< / td>
< / tr>
< tr>
< td colspan =2align =center>注:支持的图片格式:.jpeg,.jpg,.png,.gif< / td>
< / tr>
< tr>
< td colspan =2align =center>< input type =submitvalue =Create Galleryid =selectedButton/>< / td>
< / tr>
< / table>
< / form>

不错的链接:

PHP单个文件上传的基本解释不同 。 / p>

PHP文件上传与验证



PHP多个文件上传与验证(点击这里下载源代码)



PHP / jQuery多文件上传与ProgressBar和验证(点击这里下载源代码)




I've been trying to make this work for quite some time now. But I can't seem to make it work. I wanted to have a multiple image upload form with only using one input.

this is my upload.php

<?php
include("../include/session.php");

session_start();
$allowedExts = array("jpeg", "jpg", "png", "gif");
$extension = end(explode(".", $_FILES["upload"]["name"]));

if(isset($_FILES['upload']['tmp_name']))
{
    for($i=0; $i < count($_FILES['upload']['tmp_name']);$i++)
    {

        if (($_FILES["upload"]["name"] < 90000000000000000)
            && in_array($extension, $allowedExts)) {
                if ($_FILES["upload"]["error"] > 0)
                {
                    header('location: '.$error); die;
                }
                else
                {

                    if (file_exists("../icons/".$_SESSION["username"] ."/" . $_FILES["upload"]["name"]))
                    {
                    echo "error";
                    }
                    else
                    {
                        if(!is_dir("../icons/". $_SESSION["username"] ."/")) {
                            mkdir("../icons/". $_SESSION["username"] ."/");
                        }

                        $temp = explode(".",$_FILES["upload"]["name"]);
                        $file = rand(1,999999999999) . '.' .end($temp);

                        move_uploaded_file($_FILES["upload"]["tmp_name"], "../icons/". $_SESSION["username"] ."/". $file);  
                    }
                }
            }
        } else {
            echo "yep error";
        }
    }
} 
?>

if i take out the lines

if(isset($_FILES['upload']['tmp_name']))
{
    for($i=0; $i < count($_FILES['upload']['tmp_name']);$i++)
    {

With the corresponding closing bracket, it seems to work fine. The image is uploaded perfectly. But the thing is, it only allows me to upload one.

Please I really need your expertise. THank you

解决方案

Nice link on:

PHP Single File Uploading with vary basic explanation.

PHP file uploading with the Validation

PHP Multiple Files Upload With Validation (Click here to download source code)

PHP/jQuery Multiple Files Upload With The ProgressBar And Validation (Click here to download source code)

How To Upload Files In PHP And Store In MySql Database (Click here to download source code)

extract($_POST);
    $error=array();
    $extension=array("jpeg","jpg","png","gif");
    foreach($_FILES["files"]["tmp_name"] as $key=>$tmp_name)
            {
                $file_name=$_FILES["files"]["name"][$key];
                $file_tmp=$_FILES["files"]["tmp_name"][$key];
                $ext=pathinfo($file_name,PATHINFO_EXTENSION);
                if(in_array($ext,$extension))
                {
                    if(!file_exists("photo_gallery/".$txtGalleryName."/".$file_name))
                    {
                        move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"photo_gallery/".$txtGalleryName."/".$file_name);
                    }
                    else
                    {
                        $filename=basename($file_name,$ext);
                        $newFileName=$filename.time().".".$ext;
                        move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"photo_gallery/".$txtGalleryName."/".$newFileName);
                    }
                }
                else
                {
                    array_push($error,"$file_name, ");
                }
            }

and you must check your HTML code

<form action="create_photo_gallery.php" method="post" enctype="multipart/form-data">
    <table width="100%">
        <tr>
            <td>Select Photo (one or multiple):</td>
            <td><input type="file" name="files[]" multiple/></td>
        </tr>
        <tr>
            <td colspan="2" align="center">Note: Supported image format: .jpeg, .jpg, .png, .gif</td>
        </tr>
        <tr>
            <td colspan="2" align="center"><input type="submit" value="Create Gallery" id="selectedButton"/></td>
        </tr>
    </table>
</form>

Nice link on:

PHP Single File Uploading with vary basic explanation.

PHP file uploading with the Validation

PHP Multiple Files Upload With Validation (Click here to download source code)

PHP/jQuery Multiple Files Upload With The ProgressBar And Validation (Click here to download source code)

How To Upload Files In PHP And Store In MySql Database (Click here to download source code)

这篇关于多个图像上传PHP表单与一个输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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