0

你能为我的代码提供帮助吗,我需要进行多次上传,但我不能,所以请你帮助我。我需要这么糟糕。

here's my code

我多次上传表格,但它不起作用。输出是“错误数组”//HTML

<html>
<head>
    <form name="Image" enctype="multipart/form-data" action="upload.php" method="POST">
        <h1><font face="tahoma"> UPLOAD FILES</h1>
        <label for="file">Filename:</label>
        <input type="file" name="Photo[]"  accept="image/*" multiple="multiple"/><br/><br/>
        <input type="hidden" id="pageName" name="pageName">
            <script type="text/javascript">
                //get page name from parent

                var value = window.opener.pageName
                document.getElementById("pageName").value = value;
            </script>

        <INPUT type="submit" class="button" name="Submit" value=" Upload ">
        <INPUT type="reset" class="button" value="Cancel"><br/><br/>
    </form>
</head>
</html>


//PHP this is were upload is do.

<?php


include('global.php');
?>

<?

$uploadDir = 'directory/'; //Image Upload Folder

if(isset($_POST['Submit']))
    {


    $fileName = $_FILES['Photo']['name'][0];
     $fileName1 = $_FILES['Photo']['name'][1];
    $tmpName = $_FILES['Photo']['tmp_name'];
    $fileSize = $_FILES['Photo']['size'];
    $fileType = $_FILES['Photo']['type'];
    $filePath = $uploadDir . $fileName . $fileName1;


    //upload error
    if ($_FILES["Photo"]["error"] > 0)
  {
  echo "Error: " . $_FILES["Photo"]["error"] . "<br />";
  }
    //photo already exixts




else    
//insert image into DB
{


  move_uploaded_file($tmpName, $filePath);

  $filePath = addslashes($filePath);
        $filePath = stripslashes($filePath);
        $filePath = mysql_real_escape_string($filePath);

   $query = "INSERT INTO images (image , category ) VALUES ('$filePath', '$pageName')";
    mysql_query($query) or die('Error, query failed');
    echo" Upload Successful. <br/> <br/>";
            echo "Stored in: " . "directory/" . $_FILES["Photo"]["name"];
?>
  <br/><br/>
                    <img width="300" height="400" src="directory /<?=$_FILES["Photo"]["name"]?>"><br/>
<?
}
}
?>
4

1 回答 1

0

Error: Array告诉您返回的错误实际上是一个 Array 对象,而不是字符串。如果要查看实际的错误消息,则需要查看数组的全部内容。像这样print_r($_FILES["Photo"]["error"]);或循环遍历数组的东西

foreach($_FILES["Photo"]["error"] as $err) {
    echo "error: " . $err . "<br>";
}

或者您可以打印返回的第一个错误,就像您返回名称数组中的第一个文件一样echo $_FILES["Photo"]["error"][0];

于 2013-02-10T08:22:41.803 回答