简体   繁体   English

PHP照片/文件上传问题

[英]PHP Photo/File Upload Issues

Been looking around as i'm having a few issues with PHP file upload! 一直到处逛逛,因为我在上传PHP文件时遇到了一些问题! I'm trying to upload a photo or three to a database (admin_images) if the user wants to or show the photo that's already stored in the db. 我正在尝试将一张或三张照片上传到数据库(admin_images),如果用户想要或显示已存储在数据库中的照片。 I'm having some issues, below is my code I currently have, any advice is welcome. 我遇到一些问题,以下是我目前拥有的代码,欢迎提出任何建议。

 require_once 'connect/config.php'; 
 require_once 'connect/opendb.php';
 require_once 'connect/magic.quotes.php';

 $home_query = "SELECT * FROM admin"; 
$home_rt = mysql_query($home_query); 
$home_row = mysql_fetch_assoc($home_rt);

 if(isset($_POST['submit']))  {      $HomeTitle = check_input($_POST['HomeTitle']);      $HomeBio = check_input($_POST['HomeBio']);

    $home_query = mysql_query("UPDATE admin SET HomeTitle = '".$HomeTitle."', HomeBio = '".$HomeBio."' WHERE ID = 1");  


            foreach ($_FILES['file']['name'] as $f => $name)    {
                $name = strtolower($name);
                $allowedExts = array("gif", "jpeg", "jpg", "png");      $temp = explode(".", $name);        $extension = end($temp);
                if(in_array($extension, $allowedExts))      {           if($_FILES['file']['size'][$f] < 2000000)           {
                $uniqid = uniqid();

                move_uploaded_file($_FILES["file"]["tmp_name"][$f], "upload/" . $uniqid  . "." . $extension);

                mysql_query("INSERT INTO admin_images (id, HomeImage1, HomeImage2, HomeImage3) VALUES (".$last_id.", '".$uniqid .".".$extension."')");
                        }           else            {
                        }       }       else        {
                }   }   header("Location: home1.php");

}  require_once 'connect/closedb.php'; ?

In the PHP further down the page I have included: 在PHP的下一页中,我包括了:

input type="file" name="files[]" multiple

Apologies if I'm being unclear. 抱歉,如果我不清楚。 Thanks in advance. 提前致谢。

By using $_FILES['file'] you are telling the PHP to get file from input type with name "file" -the input you show has a different name (actually its an array). 通过使用$_FILES['file']您告诉PHP从名称为“ file”的输入类型获取文件-您显示的输入具有不同的名称(实际上是数组)。

it is best to dump the $_FILES array to view the actual data in it. 最好转储$ _FILES数组以查看其中的实际数据。 var_dump($_FILES);

see this . 看到这个 it gives detail process. 它给出了详细的过程。 match the format and check for any bug. 匹配格式并检查是否有错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM