php - laravel 中的“无法创建目录”错误(在服务器上)

标签 php laravel

我正在创建一个表单,用户可以通过该表单上传图片并将其与表单中的信息一起发送到服务器。在本地一切正常,但是当我将代码上传到服务器时,我开始出现错误。我更改了有关路径的所有代码,但它仍然给我一些错误,但至少我现在可以检索图片。

现在进入正题。当我提交表单时,它给我一个“无法创建”http://xxx.xx.xx/profileLogo “目录”。这是我试图将图片保存到文件夹中的时候。

这是我认为问题出处的代码:

$path = $request->file('logo')->move( Assets (“/profileLogo/”),$fileNameToStore );

Controller 的完整代码如下:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use Illuminate\Support\Facades\Storage;
use DB;
use File;

class CompanyProfileController extends Controller
{
/**
 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
    $result= DB::table('tblcompany')->get();
    if($result==null)
    {
        DB::table('tblcompany')->insert([
            'companyName' =>' ']
     );
    }
    $pic = DB::table('tblcompany')->select('logoName')->limit(1)->value('logoName');
    if($pic==null)
    {
        DB::table('tblcompany')->update(['logoName' => 'noimage.png',]);
    }
    $data['getAllDetails']= DB::table('tblcompany')->get();

    return view('companyProfile.companyProfile', $data);
}

/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
 */
public function create()
{
    //
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request)
{
    //
}

/**
 * Display the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function show($id)
{
    //
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function edit($id)
{
    //
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(Request $request)
{
//dd(asset(''));
    $this->validate($request, [
        'companyname' =>'required',
        'shortCode' =>'required',
        'telnum' =>'required',
        'emailid' =>'required',
        'address' =>'required',

    ]);

    //$file_path =  asset('') . '/profileLogo/';
    //$file_path =  asset("/profileLogo/");

    if($request->hasFIle('logo')){
        $filenameWithExt = $request->file('logo')->getClientOriginalName();
        $filename = pathinfo($filenameWithExt,PATHINFO_FILENAME);
        $extention = $request->file('logo')->getClientOriginalExtension();
        $fileNameToStore = $filename.'_'.time().'.'.$extention;
       $pic = DB::table('tblcompany')->select('logoName')->limit(1)->value('logoName');
       if($pic!='noimage.png')
       {

            //$deletePicPath = $file_path . $pic;
            //die($deletePicPath);
            //File::delete($deletePicPath );
       }



        $path = $request->file('logo')->move(
           asset("/profileLogo/"), $fileNameToStore
        );

        DB::table('tblcompany')->update(['logoPath' => $path,'logoName' => $fileNameToStore,]);

    }


    $companyname= trim($request['companyname']);
    $shortCode= trim($request['shortCode']);
    $telnum= trim($request['telnum']);
    $emailid= trim($request['emailid']);
    $address= trim($request['address']);

    DB::table('tblcompany')->update(
            ['companyName' => $companyname,
            'shortCode' => $shortCode,
            'phoneNo' => $telnum,
            'emailAddress' => $emailid,
            'contactAddress' => $address,]
        );

        return redirect('/company-profile')->with('message','Form Updated');
}

/**
 * Remove the specified resource from storage.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function destroy($id)
{
    //
}

那么如何才能成功进入文件夹并存储图片呢?

最佳答案

更改要保存文件的文件夹的权限。对于 Linux:

chmod a+rwx folder_name -R

它将更改 folder_name 和包含的所有文件夹的权限。 您必须以系统根身份执行此操作。

对于窗口:

C:\>icacls "D:\path_to_folder" /grant John:(OI)(CI)F /T

关于php - laravel 中的“无法创建目录”错误(在服务器上),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49404350/

相关文章:

php - 当我的应用程序关闭时,GCM 消息不会出现在我的应用程序中

php - Behat 3.0 功能文件夹/路径

laravel - Laravel 中的 VueJS 设置

php - Docker - NGINX 容器转发到 PHP-FPM 容器

php - Laravel 生成 URL 函数

php - MySQL 中的特殊表

php - 警告 : Illegal offset type php

php - 如何使用php从特定电子邮件地址获取邮件信息并将标题信息存储到mysql数据库中

php - 将使用php和Mysql登录的特定用户的所有数据导出到excel表中

php - Laravel 验证从列中获取值并将其与另一个表列进行比较