无法打开流:没有此类文件或目录问题

时间:2017-08-30 11:46:52

标签: php laravel ftp

抱歉,我不太懂英文

我需要在其他VPS中上传图片文件。

我的框架是Laravel 5.2。

提交后显示此错误:

ftp_put(/tmp/phpzGLEyw): failed to open stream: No such file or directory

此代码:

$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
foreach($file as $files){
            $filename = $files->getClientOriginalName();
            $extension = $files->getClientOriginalExtension();
            $picture = sha1($filename . time()) . '.' . $extension;
            $folder = Auth::guard('vendor')->user()->id;

            $url = '/public_html/';                

            if (ftp_put($ftp_conn, $url . $picture, $files, FTP_ASCII))
            {
                $m = "Successfully uploaded.";
            }
            else
            {
                $m = "Error uploading.";
            }
}

ftp_close($ftp_conn);

例如:

的print_r($文件):

Illuminate\Http\UploadedFile Object ( [test:Symfony\Component\HttpFoundation\File\UploadedFile:private] => [originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => Screenshot from 2017-03-23 13-41-47.png [mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => image/png [size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 6194 [error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0 [pathName:SplFileInfo:private] => /tmp/phpLqy7Bt [fileName:SplFileInfo:private] => phpLqy7Bt )

问题在哪里?

1 个答案:

答案 0 :(得分:0)

好.. $ file是一个对象UploadedFile,没有本地资源..尝试连接远程主机并确认url路径存在并正确写入权限。并将ftp_put中的$文件更改为$ files-> path()

检查/ tmp / phpzGLEyw(文件数组中的文件)是否存在于本地主机中可能删除文件:p

好阿里!