i use elfinder to upload file throught FTP driver, but i can not upload file to server, elfinder show messagers dialog "unabled to upload file, permission denied". I have take owership for the user use FTP but not affected:(, please help me
$newname should be full path to a new file. But in your script it is a relative path that seems to point somewhere inside /tmp
I solved this problem by adding extra configurations to elfinder root. For example:
$root = array(
// -------------------------------
'driver' => 'FTP',
'host' => 'ftp_ip',
'user' => 'username',
'pass' => 'password',
// -------------------------------
'port' => 21,
'mode' => 'passive',
'alias' => 'folder_alias,
'owner' => true,
'tmbPath' => '/tmp',
'tmpPath' => '/tmp',
'dirMode' => 0777,
'fileMode' => 0777
);
Related
I have managed to configure my sftp in the 'config/filesystems.php' file:
'remote-sftp' => [
'driver' => 'sftp',
'host' => env('SFTP_HOST'),
'username' => env('SFTP_USERNAME'),
'password' => env('SFTP_PASSWORD'),
'root' => '/var/www/html/files/current',
'visibility' => 'public',
'permPublic' => 0644,
'timeout' => 30,
],
An sftp account was created on the remote server (usert) and I successfully manage to upload the file to the server, but, the problem is that the files is being stored in the wrong folder. My code to upload the file :
$fileName = $id_number . '_tps_' . $datetime . '.' . $request->file('file')->extension();
Storage::disk('remote-sftp')->put($fileName, fopen($request->file('file'), 'r+'), 'public');
I expect the file to be stored in '/var/www/html/files/current' as specified in 'config/filesystems.php' but i find the file is actually stored in '/home/usert'. How to I get it to save in the '/var/www/html/files/current'?
I have a problem uploading a file in Laravel 8.81.0 on ftp.
I have this form in the home.blade.php file:
<form action="{{addFile}}" method="post" enctype="multipart/form-data">
#method('PUT')
#csrf
<p>
<input type="file" name="profile_image" />
</p>
<button type="submit" name="submit">Submit</button>
</form>
I have yes in the controller
if($request->hasFile('profile_image')) {
//get filename with extension
$filenamewithextension = $request->file('profile_image')->getClientOriginalName();
//get filename without extension
$filename = pathinfo($filenamewithextension, PATHINFO_FILENAME);
//get file extension
$extension = $request->file('profile_image')->getClientOriginalExtension();
//filename to store
$filenametostore = $filename.'_'.uniqid().'.'.$extension;
//Upload File to external server
Storage::disk('ftp')->put($filenametostore, fopen($request->file('profile_image'), 'r+'));
//Store $filenametostore in the database
}
in the .env file I added
FTP_HOST=xxx
FTP_USERNAME=xxx
FTP_PASSWORD=xxx
In the filesystems.php file
'disks' => [
'ftp' => [
'driver' => 'ftp',
'host' => env(xxx),
'username' => env(xxx),
'password' => env('xxx'),
'root' => '/public/' // for example: /var/www/html/dev/images
],
But anyway after uploading the file I get the error: ValueError
Path cannot be empty.
I am using file transfer for the first time, so I would be grateful for a hint of what I am doing wrong
I mention that directories are set to allow file writing
'ftp' => [
'driver' => 'ftp',
'host' => 'FTP_HOST',
'username' => 'FTP_USERNAME',
'password' => 'FTP_PASSWORD',
'passive' => 'false',
'ignorePassiveAddress' => true,
'port' => 21,
'root' => 'public_html/storage/app/public/Your_Folder/' // for example: /public_html/images
]
//file will save in storage directory you need to link storage for access your files
$path = $file->store('Your Folder','ftp');
I am trying to upload a file to a public folder which was working lately but now it is showing below error:
Disk [public] does not have a configured driver.
I tried checking for configured driver in config/filesystems.php but, it is already set there. I am not getting where the issue might be.
Upload code:
public function upload(ProductImageRequest $request, Product $product)
{
$image = $request->file('file');
$dbPath = $image->storePublicly('uploads/catalog/'.$product->id, 'public');
if ($product->images === null || $product->images->count() === 0) {
$imageModel = $product->images()->create(
['path' => $dbPath,
'is_main_image' => 1, ]
);
} else {
$imageModel = $product->images()->create(['path' => $dbPath]);
}
return response()->json(['image' => $imageModel]);
}
Code in config/filesystems.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
i use this code for moving the picture and storing its name you may want to give it a shot
//get icon path and moving it
$iconName = time().'.'.request()->icon->getClientOriginalExtension();
$icon_path = '/category/icon/'.$iconName;
request()->icon->move(public_path('/category/icon/'), $iconName);
$category->icon = $icon_path;
i usually move the image then store its path in db and this is what my code shows you can edit it as desired
When I run command: php artisan storage:link, this creates folder /public/storage.
then I have code, which handles uploaded file:
// get file original name and extension here, then generate file new name $fileNameToStore
// set file path
$path = $request->file('my_file')->storeAs('public/uploaded_imgs', $fileNameToStore);
Code works and uploaded file appears in /storage/app/public/uploaded_imgs/ folder, which is nice, though there is nothing in /public/storage folder.
Why there is not uploaded_imgs folder in /public/storage directory? What I'm doing wrong?
In config/filesystems.php, you could do this... change the root element in public
Note : instead of upload you can use your folder name
'disks' => [
'public' => [
'driver' => 'local',
'root' => public_path() . '/uploads',
'url' => env('APP_URL').'/public',
'visibility' => 'public',
]
]
and you can access it by
Storage::disk('public')->put('uploaded_imgs', $request->file('my_file'));
or
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path(),
],
'uploads' => [
'driver' => 'local',
'root' => public_path() . '/uploads',
],
]
Then use it :
Storage::disk('uploads')->put('filename', $file_content);
Try this:
Storage::disk('public')->put('uploaded_imgs', $request->file('my_file'));
hopefully it will work.
When you run php artisan storage:link command, Laravel generates a "storage" symlink under "public" folder which directs to /storage/app/public so your code is correct.
There is no public/storage directory, its a symlink which directs to /storage/app/public which is where your uploaded_imgs folder has been generated.
public/storage => /storage/app/public
You can use the following code to upload a file:
$file = $request->file('my_file');
$fileNameWithoutExtension = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
$path = "public/uploaded_imgs/" + $fileNameWithoutExtension +"."+$file->getClientOriginalExtension();
Storage::disk('local')->put($path, file_get_contents($file), 'public');
I'm starting to work with elFinder and I don't know why but I get this error "Unable to connect to backend.Backend not found.". The connector.php looks like this
$opts = array(
// 'debug' => true,
'roots' => array(
array(
'driver' => 'LocalFileSystem', // driver for accessing file system (REQUIRED)
'path' => '../files/', // path to files (REQUIRED)
'URL' => dirname($_SERVER['PHP_SELF']) . '/../files/', // URL to files (REQUIRED)
'uploadDeny' => array('all'), // All Mimetypes not allowed to upload
'uploadAllow' => array('image', 'text/plain'),// Mimetype `image` and `text/plain` allowed to upload
'uploadOrder' => array('deny', 'allow'), // allowed Mimetype `image` and `text/plain` only
'accessControl' => 'access' // disable and hide dot starting files (OPTIONAL)
)
)
);
And the path to the file is: myproject >> dashboard >> plugins >> elfinder . What can I do to solve the problem with backend connection?
It is HTTP error "404 Not Found". Please check your connector URL.