Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.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
Javascript 在laravel 5.3中上载文件夹中的文件时出现问题?_Javascript_Laravel_Laravel 5 - Fatal编程技术网

Javascript 在laravel 5.3中上载文件夹中的文件时出现问题?

Javascript 在laravel 5.3中上载文件夹中的文件时出现问题?,javascript,laravel,laravel-5,Javascript,Laravel,Laravel 5,我试图上传在laravel图像,但我得到错误,当我上传在文件夹中的图像,当我上传图像,并点击提交按钮,这给我上传文件的问题,我想这一行有错误 move_uploaded_file($imageName, $moveable_file); 这是我的usercontrolle.php文件 public function dropzone(Request $request) { $user = Auth::user()->toArray(); $user_id = $user

我试图上传在laravel图像,但我得到错误,当我上传在文件夹中的图像,当我上传图像,并点击提交按钮,这给我上传文件的问题,我想这一行有错误

 move_uploaded_file($imageName, $moveable_file);
这是我的usercontrolle.php文件

public function dropzone(Request $request)
{
    $user = Auth::user()->toArray();
    $user_id = $user['id'];
    $type = 'photo';
    $type_id=0;
    $data = $_FILES["image"];

    //dd($data);
    $doc_id = $_POST["doc_id"];
    $doc_name = $_POST["doc_name"];
    if($doc_id)
    {   $img_id=$doc_id;
        $img_name=$doc_name;
        $response = $this->userService->deleteDocument($img_id,$img_name,$user_id,$type,$type_id);
    }
  // $image_array_1 = explode(";", $data);
  // $image_array_2 = explode(",", $image_array_1[1]);
  // $data = base64_decode($image_array_2[1]);

  $storage_path = env('DOCUMENT_STORAGE_PATH');
  $profile_upload_dir = str_replace(["/","\\"], [DIRECTORY_SEPARATOR,DIRECTORY_SEPARATOR], $storage_path); 

    if($type_id != '0'){
        $destination_path = $profile_upload_dir . $user_id ."\\". $type."\\". $type_id;
        $destination_path = str_replace(["/","\\"], [DIRECTORY_SEPARATOR,DIRECTORY_SEPARATOR], $destination_path);   
    }else{
        $destination_path = $profile_upload_dir . $user_id ."\\". $type;
        $destination_path = str_replace(["/","\\"], [DIRECTORY_SEPARATOR,DIRECTORY_SEPARATOR], $destination_path);   
    }
        if(!is_dir($destination_path)) {
            mkdir($destination_path, 0777,true);
        }
        $imageName = time() . '.png';
       // dd($imageName);
        $moveable_file = str_replace(["/","\\"], [DIRECTORY_SEPARATOR,DIRECTORY_SEPARATOR], $destination_path.'\\'.$imageName); 
        //dd($moveable_file);
        move_uploaded_file($imageName, $moveable_file);
        // file_put_contents($moveable_file, $data);
        //$image_file = addslashes(file_get_contents($moveable_file));
        $user = Auth::user()->toArray();
          //dd($user);
        $user_id = $user['id'];
        $type_id = 0;
        if(isset($photo['type_id']) && !empty($photo['type_id'])){
            $type_id = $photo['type_id'];
        }
        //$photo['file']=$_FILES['photoimg'];
        $photo['type']='photo';
        $result = $this->userService->storeUserDocuments($imageName, $photo['type'], $type_id, $user_id);
        // echo '<img src="data:image/png;base64,'.base64_encode($data).'" data-action="zoom" class="pull-left" style="height: 130px;width:130px;">';

}
公共功能dropzone(请求$Request)
{
$user=Auth::user()->toArray();
$user_id=$user['id'];
$type='photo';
$type_id=0;
$data=$\u文件[“图像”];
//dd(数据);
$doc\u id=$\u POST[“doc\u id”];
$doc\u name=$\u POST[“doc\u name”];
如果($doc\u id)
{$img_id=$doc_id;
$img\u name=$doc\u name;
$response=$this->userService->deleteDocument($img\u id、$img\u name、$user\u id、$type、$type\u id);
}
//$image_array_1=分解(“;”,$data);
//$image\u array\u 2=分解(“,”,$image\u array\u 1[1]);
//$data=base64_解码($image_数组_2[1]);
$storage\u path=env('DOCUMENT\u storage\u path');
$profile\u upload\u dir=str\u replace([“/”,“\\”],[DIRECTORY\u SEPARATOR,DIRECTORY\u SEPARATOR],$storage\u path);
如果($type_id!=“0”){
$destination\u path=$profile\u upload\u dir.$user\u id.“\\\”$type.\\”$type\u id;
$destination\u path=str\u replace([“/”,“\\”],[目录分隔符,目录分隔符],$destination\u path);
}否则{
$destination\u path=$profile\u upload\u dir.$user\u id.“\\\”$type;
$destination\u path=str\u replace([“/”,“\\”],[目录分隔符,目录分隔符],$destination\u path);
}
如果(!is_dir($destination_path)){
mkdir($destination_path,0777,true);
}
$imageName=time().'.png';
//dd($imageName);
$moveable\u file=str\u replace([“/”,“\\”],[DIRECTORY\u SEPARATOR,DIRECTORY\u SEPARATOR],$destination\u path.'\\'.$imageName);
//dd($moveable_file);
移动上传的文件($imageName,$moveable\u file);
//文件内容($moveable\u file,$data);
//$image\u file=addslashes(文件获取内容($moveable\u文件));
$user=Auth::user()->toArray();
//dd(用户);
$user_id=$user['id'];
$type_id=0;
if(设置($photo['type\u id'])和&!empty($photo['type\u id'])){
$type_id=$photo['type_id'];
}
//$photo['file']=$\u文件['photoimg'];
$photo['type']='photo';
$result=$this->userService->storeUserDocuments($imageName,$photo['type'],$type\u id,$user\u id);
//回声';
}
您还可以使用上载图像。 首先,在您的laravel项目上使用 作曲家需要干预/图像 安装后,打开config/app.php,然后将它们添加到$providers数组中

Intervention\Image\ImageServiceProvider::class
另外,将此包的外观添加到$Alias数组中

'Image' => Intervention\Image\Facades\Image::class
在此之后,您就可以添加图像了 将此添加到控制器中

use Intervention\Image\Facades\Image;
//Handle the user upload of avatar
    if($request->hasFile('avatar')){
        $avatar = $request->file('avatar');

        $filename = time().'.'.$avatar->getClientOriginalExtension();  //use time to create file name
        Image::make($avatar)->resize(300,300)->save( public_path('/images/'.$filename) );


        $user->avatar = $filename;
       //Handle the user upload of avatar
    if($request->hasFile('avatar')){
        $avatar = $request->file('avatar');

        $filename = time().'.'.$avatar->getClientOriginalExtension();
        Image::make($avatar)->resize(300,300)->save( public_path('/images/'.$filename) );


        $user->avatar = $filename;
       // $user->save(); //To save the name of the file in the database
    }
    }
下面是如何添加图像的示例,请在控制器中使用此示例

use Intervention\Image\Facades\Image;
//Handle the user upload of avatar
    if($request->hasFile('avatar')){
        $avatar = $request->file('avatar');

        $filename = time().'.'.$avatar->getClientOriginalExtension();  //use time to create file name
        Image::make($avatar)->resize(300,300)->save( public_path('/images/'.$filename) );


        $user->avatar = $filename;
       //Handle the user upload of avatar
    if($request->hasFile('avatar')){
        $avatar = $request->file('avatar');

        $filename = time().'.'.$avatar->getClientOriginalExtension();
        Image::make($avatar)->resize(300,300)->save( public_path('/images/'.$filename) );


        $user->avatar = $filename;
       // $user->save(); //To save the name of the file in the database
    }
    }

您收到的错误消息是什么?能否添加错误日志?