Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php laravel上的jquery文件上载验证错误_Php_Laravel_Validation_Post_Jquery File Upload - Fatal编程技术网

Php laravel上的jquery文件上载验证错误

Php laravel上的jquery文件上载验证错误,php,laravel,validation,post,jquery-file-upload,Php,Laravel,Validation,Post,Jquery File Upload,使用laravel 5.5上的jquery上传文件 当我上传一张图片时,我发现了一个错误 POST 500(内部服务器错误) 细节是 {,…} exception : "ErrorException" file : "I:\AppServ\www\comefour\app\Http\Controllers\UploadController.php" line : 8 message : "Declaration of App\Http\Controllers\UploadController::

使用laravel 5.5上的jquery上传文件 当我上传一张图片时,我发现了一个错误

POST 500(内部服务器错误)

细节是

{,…}
exception
:
"ErrorException"
file
:
"I:\AppServ\www\comefour\app\Http\Controllers\UploadController.php"
line
:
8
message
:
"Declaration of App\Http\Controllers\UploadController::validate($uploaded_file, $file, $error, $index) should be compatible with App\Http\Controllers\Controller::validate(Illuminate\Http\Request $request, array $rules, array $messages = Array, array $customAttributes = Array)"
trace
:
[{file: "I:\AppServ\www\comefour\app\Http\Controllers\UploadController.php", line: 8,…},…]
我的控制器代码来自demo UploadHandler.php

public function validate($uploaded_file, $file, $error, $index) {

    if ($error) {
        $file->error = $this->get_error_message($error);
        return false;
    }
    $content_length = $this->fix_integer_overflow(
        (int)$this->get_server_var('CONTENT_LENGTH')
    );
    $post_max_size = $this->get_config_bytes(ini_get('post_max_size'));
    if ($post_max_size && ($content_length > $post_max_size)) {
        $file->error = $this->get_error_message('post_max_size');
        return false;
    }
    if (!preg_match($this->options['accept_file_types'], $file->name)) {
        $file->error = $this->get_error_message('accept_file_types');
        return false;
    }
    if ($uploaded_file && is_uploaded_file($uploaded_file)) {
        $file_size = $this->get_file_size($uploaded_file);
    } else {
        $file_size = $content_length;
    }
    if ($this->options['max_file_size'] && (
            $file_size > $this->options['max_file_size'] ||
            $file->size > $this->options['max_file_size'])
        ) {
        $file->error = $this->get_error_message('max_file_size');
        return false;
    }
    if ($this->options['min_file_size'] &&
        $file_size < $this->options['min_file_size']) {
        $file->error = $this->get_error_message('min_file_size');
        return false;
    }
    if (is_int($this->options['max_number_of_files']) &&
            ($this->count_file_objects() >= $this->options['max_number_of_files']) &&
            // Ignore additional chunks of existing files:
            !is_file($this->get_upload_path($file->name))) {
        $file->error = $this->get_error_message('max_number_of_files');
        return false;
    }
    $max_width = @$this->options['max_width'];
    $max_height = @$this->options['max_height'];
    $min_width = @$this->options['min_width'];
    $min_height = @$this->options['min_height'];
    if (($max_width || $max_height || $min_width || $min_height)
       && preg_match($this->options['image_file_types'], $file->name)) {
        list($img_width, $img_height) = $this->get_image_size($uploaded_file);

        // If we are auto rotating the image by default, do the checks on
        // the correct orientation
        if (
            @$this->options['image_versions']['']['auto_orient'] &&
            function_exists('exif_read_data') &&
            ($exif = @exif_read_data($uploaded_file)) &&
            (((int) @$exif['Orientation']) >= 5)
        ) {
            $tmp = $img_width;
            $img_width = $img_height;
            $img_height = $tmp;
            unset($tmp);
        }

    }
    if (!empty($img_width)) {
        if ($max_width && $img_width > $max_width) {
            $file->error = $this->get_error_message('max_width');
            return false;
        }
        if ($max_height && $img_height > $max_height) {
            $file->error = $this->get_error_message('max_height');
            return false;
        }
        if ($min_width && $img_width < $min_width) {
            $file->error = $this->get_error_message('min_width');
            return false;
        }
        if ($min_height && $img_height < $min_height) {
            $file->error = $this->get_error_message('min_height');
            return false;
        }
    }
    return true;
}

您将您的
validate()
方法命名为
validate
,这是控制器上的一个“保留”方法,它正好期望:

public function validate(Request $request, array $rules,
                         array $messages = [], array $customAttributes = [])
你可以看到来源


我建议您将该方法重命名为其他方法
validateFile
可能?

您将自己的
validate()
方法命名为
validate
,这是控制器上的一种“保留”方法,它正是这样期望的:

public function validate(Request $request, array $rules,
                         array $messages = [], array $customAttributes = [])
你可以看到来源


我建议您将该方法重命名为其他方法<代码>验证文件可能?

我在这里没有看到任何与jQuery验证插件有关的内容。我在这里看不到任何与jQuery验证插件有关的东西。编辑标签。你拯救了我的一天~你拯救了我的一天~