laravel5.1中文件上传操作出现错误
为情所困
为情所困 2017-05-16 16:53:51
[PHP讨论组]


以下是代码(想问一下该如何修改。自己小白一个,先提前谢谢大家!):
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class RequestController extends Controller
{

public function getFileupload(){
    $postUrl='/laravelFirst/public/index.php/request/fileupload';
    $csrf_field=csrf_field();
    $html=<<<FILE
    <form action="$postUrl" method="post" enctype="multipart/form-data">
    $csrf_field
    <input type="file" name="file"><br/>
    <input type="submit" value="提交">
    </form>

FILE;

    return $html;          
}
public function postFileupload(Request $request){
    if(!$request->hasFile('file')){
        exit('上传文件为空!');
    }
    $file=$request->file('file');
    if(!$file->isValid()){
        exit('上传文件出错!');
    }
    $destPath = realpath(public_path('images'));
    if(!file_exists($destPath)){
    mkdir($destPath,0755,true);
}
    $filename=$file->getClientOriginalName();
    if(!$file->move($destPath,$filename)){
        exit('保存文件失败!');
    }
    exit('文件上传成功!');
}

}

为情所困
为情所困

全部回复(2)
过去多啦不再A梦

你打印那个destPath看看

習慣沉默

laravel上传文件还是使用Storage这个Facade吧,他可以自己处理文件夹创建之类的问题

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号