0

我有一次上传和多次上传。当我在大小为 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 />';
    }

}
4

1 回答 1

0

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

于 2012-04-25T18:16:35.953 回答