Php 如何从数据库中插入、检索多个图像

Php 如何从数据库中插入、检索多个图像,php,Php,这是提供图像路径的php代码, 我从另一个ios应用程序获取的多个图像,如何将这些图像插入到具有不同名称的数据库中并显示 <?php $myparam = $_POST['userfile']; //getting multiple image Here //$mytextLabel= $_POST['filenames'] //getting textLabe Here //echo $myparam; //echo $mytextLabel; $target_path

这是提供图像路径的php代码, 我从另一个ios应用程序获取的多个图像,如何将这些图像插入到具有不同名称的数据库中并显示

<?php

$myparam = $_POST['userfile'];     //getting multiple image Here

//$mytextLabel= $_POST['filenames']   //getting textLabe Here
//echo $myparam;
//echo $mytextLabel;
$target_path  = "uploads/";
$target_path  = $target_path . basename( $_FILES['userfile']['name']);

if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)) {
    echo "Success ! The file has been uploaded";
    //insert query will run here right?
   //but how to get those multiple images and save it m not getting

} else{
    echo "There was an error uploading the file, please try again!";
}
?>

您可以使用。
此类为您管理文件上载。简而言之,它管理上传的文件,并允许您对该文件执行任何操作,特别是如果它是一个图像,并且可以执行任意次数

它是在您的站点中快速集成文件上传的理想类。如果文件是图像,可以通过多种方式进行转换、调整大小和裁剪。您还可以应用过滤器、添加边框、文本、水印等。。。例如,这就是你所需要的画廊脚本。支持的格式有PNG、JPG、GIF和BMP

这是一个示例类:

class UploadFile
{

    protected $uploadFileModel;

    public function __construct()
    {
        $this->uploadFileModel = new UploadFileModel();
    }

    public function insert($params)
    {
        $handle = new upload($params['file'], 'fa_IR');
        $handle->file_max_size = '20000000';
        $handle->allowed = array(
            'image/png',
            'image/jpeg',
            'image/gif');
        $handle->mime_check = TRUE;
        if ($handle->uploaded) {
            $handle->process($params['file_path']);
            if ($handle->processed) {
                $params['file_name'] = $handle->file_dst_name;
                // insertToDB is a function that insert data to database
                $insToDB = $this->insertToDB(array(
                    'title' => $params['title'],
                    'file_name' => $params['file_name'],
                    'path' => $params['path'],
                    'created_at' => $params['created_at']
                ));
                if ($insToDB !== FALSE) {
                    return intval($insToDB);
                } else {
                    unlink($params['file_path'] . $params['file_name']);
                    return FALSE;
                }
            }
        }
        return $handle->error;
    }

    public function insertToDB($params)
    {
        return $this->uploadFileModel->insert($params);
    }

    public function showForm()
    {
        $str = '<input type="file" id="fileToUpload" name="fileToUpload">';
        return $str;
    }
}

因为,Ashish提供的数据/代码不多。我从我这边假设

ImageUpload.php

<?
extract($_POST);
// This will count total images selected.
$TotalImage = count($_FILES['userfile']['name']);

for($i = 0;$i<$TotalImage;$i++)
{ 
  $image_name = $_FILES['userfile']['name'][$i];
    $target_path = "uploads/".$imagename;

  if(move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $target_path))
  {
    //Write Query Here To Insert Into Database
  }
}
?>
首先,您需要使用
enctype=“multipart/form data”
上传图像。 其次,您需要将
name
声明为数组类型。(因为您正在上载多个图像)


SubmitImageUpload.php

<?
extract($_POST);
// This will count total images selected.
$TotalImage = count($_FILES['userfile']['name']);

for($i = 0;$i<$TotalImage;$i++)
{ 
  $image_name = $_FILES['userfile']['name'][$i];
    $target_path = "uploads/".$imagename;

  if(move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $target_path))
  {
    //Write Query Here To Insert Into Database
  }
}
?>


而且,由于您没有向我们提供您的数据库结构,因此,我不能假设您的数据库结构并编写代码进行检索。

我感到困惑。那你对哪一部分有意见?代码似乎与您询问的内容不匹配。如何获取多个图像以及如何插入它,我在这里结结巴巴地问您的代码Ashish在哪里,您尝试过多个图像上载?我想你被困在丝绸板交易中了嘿,穆罕默德,你怎么知道他的项目中有MVC结构?哦,是的。。。我很抱歉,但这是一个答案,你可以在没有MVC的情况下编写它的函数。
<?
extract($_POST);
// This will count total images selected.
$TotalImage = count($_FILES['userfile']['name']);

for($i = 0;$i<$TotalImage;$i++)
{ 
  $image_name = $_FILES['userfile']['name'][$i];
    $target_path = "uploads/".$imagename;

  if(move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $target_path))
  {
    //Write Query Here To Insert Into Database
  }
}
?>