【问题标题】:PHP multifile uploadPHP多文件上传
【发布时间】:2012-05-06 11:18:50
【问题描述】:

我有一次上传和多次上传。 当我在大小为 6MB 的文件上尝试时,单次上传有效。

如果我尝试对 6MB 文件进行多文件上传,多个或仅 1 个,它不起作用。

有什么想法吗?我尝试设置超时:

$messages = array();
$errors = array();

$upload_dir = '.';
if(isset($_FILES['file']['tmp_name'])){
    //Number of uploaded files.
    $num_files = count($_FILES['file']['tmp_name']);

    //loop over array of files
    for($i=0; $i<$num_files; $i++){

        //check if there is a file in the array.
        if(!is_uploaded_file($_FILES['file']['tmp_name'][$i])){
            //echo $_FILES['file']['tmp_name'][$i].': Upload Failed!';

        }else{
            //echo $_FILES['file']['tmp_name'][$i].': Upload good!';
            //lets insert the data into the DB.
            $filename = stripslashes($_FILES['file']['name'][$i]);
            $extension = getExtension($filename);
            $description = $_POST['description'][$i];

            if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
            {
                //print error message
                $error[$i] = $filename.': '.'Unknown file extension! ';

            }
            else
            {
                //get the size of the image in bytes
                //$_FILES['image']['tmp_name'] is the temporary filename of the file
                //in which the uploaded file was stored on the server
                $size=filesize($_FILES['file']['tmp_name'][$i]);


                //compare the size with the maxim size we defined and print error if bigger
                if ($size > MAX_SIZE*1024)
                {
                    //echo '<h1>You have exceeded the size limit of 100MB!</h1>';
                    $errors[$i]=$filename.': You have exceeded the size limit of 100MB';
                }

                //we will give an unique name, for example the time in unix time format
                $time = time()+$i;
                $image_name=$time.'.'.$extension;

                //the new name will be containing the full path where will be stored (images folder)
                $newname='D:\\uploads\\'.$image_name;
                //$newname=$image_name;
                //we verify if the image has been uploaded, and print error instead
                $copied = copy($_FILES['file']['tmp_name'][$i], $newname);
                if (!$copied)
                {
                    $messages[$i]= $filename.': '.'Copy unsuccessful!';
                    //echo 'Copy unsuccessful!';

                }else{
                    $messages[$i]= $filename.': '.'Copy successful!';
                    //get image information here.
                    $fileInfo = getimagesize($newname);
                    $mySize = $fileInfo[0];
                    $mimetype = image_type_to_mime_type($fileInfo[2]);
                    $dimensions = $fileInfo[3];
                    savePhotoInfo($image_name,$dimensions, $description,$mySize);
                    createThumb('D:\\uploads\\', 'D:\\uploads\\thumbnails\\', '180',$image_name);
                    //echo 'Copy successful!';
                }
            }
        }
    }

    echo 'Upload results:';
    echo '<br />';

    for($x=0;$x<count($messages);$x++){
        echo $messages[$x];
        echo '<br />';
    }

    echo 'Upload errors:';
    echo '<br />';
    for($x=0;$x<count($errors);$x++){
        echo $errors[$x];
        echo '<br />';
    }

}

【问题讨论】:

  • “它不起作用”是什么意思?有什么错误吗?
  • 意思是,没有错误,没有“文件太大”,什么都没有。它只是运行并停止/完成。文件未上传。
  • 你的Upload results: 输出是什么?

标签: php upload


【解决方案1】:

你看php.ini,上传大小的配置吗?

【讨论】:

  • 仅供参考,向原始发帖人提问适合发表评论,但不适合自己的答案。
猜你喜欢
  • 2013-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-09
  • 2012-05-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多