简体   繁体   English

将多个图像上传到Apache服务器上的mysql数据库

[英]Uploading multiple images to mysql database on Apache server

I have to upload around 3000 images into mysql database, on Apache server. 我必须将大约3000张图片上传到Apache服务器上的mysql数据库中。 (I know some of you will say it is not wise to insert images to table instead of using url, but i was forced to do that) Anyway, my script is working well when I am uploading around 20 images. (我知道你们中有些人会说将图像插入表中而不使用url是不明智的,但是我被迫这样做)无论如何,当我上传大约20张图像时,我的脚本运行良好。 When I am trying to upload around 40 images, it insert only 18-20 images. 当我尝试上传大约40张图片时,它仅插入18-20张图片。 If I am trying to upload 50+ images, no image is inserted and the script not working at all. 如果我要上传50张以上的图片,则不会插入图片,并且脚本根本无法正常工作。 I tried to increase the "max" upload/import/session/query values in some configuration files such "php.ini", "conf" etc, but I think I am missing the correct fix. 我尝试增加某些配置文件(例如“ php.ini”,“ conf”等)中的“最大”上载/导入/会话/查询值,但我想我缺少正确的修复程序。

Can somebody give me direction? 有人可以给我指示吗?

My source code: 我的源代码:

HTML: HTML:

<form action="" method="POST" enctype="multipart/form-data">
   <input type="file" name="userfile[]" multiple/>
   <input type="submit" value="Submit"/>
 </form>

PHP: PHP:

if(!isset($_FILES['userfile']))
{
    echo '<p>Please select a file</p>';
}
else
{
    try    {
        upload();
        echo '<p>Thank you for submitting</p>';
    }
    catch(Exception $e)
    {
        echo '<h4>'.$e->getMessage().'</h4>';
    }
}


function upload(){

        foreach($_FILES['userfile']['tmp_name'] as $key => $tmp_name ){


            $imgfp = fopen($_FILES['userfile']['tmp_name'][$key], 'rb');


            $nameTemp = $_FILES['userfile']['name'][$key];

            $name = preg_replace( '/\.[a-z0-9]+$/i' , '' , $nameTemp );

            /*** connect to db ***/
            $dbh = new PDO("mysql:host=localhost;dbname=testYossi", 'root', 'password');

            /*** set the error mode ***/
            $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

            /*** our sql query ***/
            $stmt = $dbh->prepare("INSERT INTO pictures (picNmae , picData) VALUES (? ,?)");

            $stmt->bindParam(1, $name);
            $stmt->bindParam(2, $imgfp, PDO::PARAM_LOB);

            $stmt->execute();       
    }               
}

Have you checked your upload_max_filesize and max_file_uploads values in the configuration of php? 您是否检查了php配置中的upload_max_filesizemax_file_uploads值? Use phpinfo() . 使用phpinfo()

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

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