gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 04:06:46 25 4
gpt4 key购买 nike

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

现在进入正题。当我提交表单时,它给我一个“无法创建”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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com