I am trying to upload a file from my local to FTP server using laravel
'ftp' => [
'driver' => 'ftp',
'host' => env('FTP_HOST'),
'username' => env('FTP_USERNAME'),
'password' => env('FTP_PASSWORD'),
'port' => '21',
'passive' => false,
'root' => 'c:/POSActiveAutoInsert/WEBSales_In/' // for example: /var/www/html/dev/images
//
],
In my controller
Storage::disk('ftp')->put('test.txt', $file);
But when I run this, it says
Root is invalid or does not exist: c:/POSActiveAutoInsert/WEBSales_In/
I have tried FTP using Filezilla it works fine
The FTP account I am using takes you directly to c:/POSActiveAutoInsert/WEBSales_In/ this folder. This WEBSales_In is the root folder for this FTP user that I am using. Can't figure out what the root path would be, or am I doing something wrong other than this.
Cheers
You can try this in your controller
$path = $request->your_variable_name->storeAs('text', '$file', ['disk' => 'ftp']);
Related
I am trying to create a file on a sFtp server:
Storage::disk('backup')->put('text.txt', 'My Text');
Unfortunately, I only get the following error message back, which I can't do anything with:
League\Flysystem\UnableToWriteFile
Unable to write file at location: text.txt. not able to write the file`
I have checked the permissions for the directory, they are ok.
My Filesystem config:
'backup' => [
'driver' => 'sftp',
'host' => env('SFTP_HOST'),
// Settings for basic authentication...
'username' => env('SFTP_USERNAME'),
'password' => env('SFTP_PASSWORD'),
'throw' => true,
],
I try to upload a video file to my download server with FTP file system in laravel but I have a this error:
League\Flysystem\ConnectionRuntimeException: Could not connect to host: myip, port:21 in file /home/test/domains/myhost/laravel/vendor/league/flysystem/src/Adapter/Ftp.php on line 140
in my filesytem.php
'ftp' => [
'driver' => 'ftp',
'host' => 'myip',
'username' => 'myusername',
'password' => 'mypass',
'port' => 21,
],
how to fix this error
FTP port:21 is for pass control information.
Did you try port:20 ?
im using sftp because when i using ftp is error in port too. and don't forget too enable ftp in php.ini
'sftp' => [
'driver' => 'sftp',
'host' => 'xxx.xxx.com',
'username' => 'user',
'password' => 'pass',
'root' => ' xxx' , // for example: /public_html/images
I fix this issue by enabling an FTP extension in my server.
I need to get list of all directories from the FTP server.
After successful FTP driver setup, Storage::allDirectories() method is returning all directories from root directory. I have also tried to use:
Storage::directories('/', true)
Which should also return recursive values but it's the same case.
Does anyone have any idea what should be problem?
This is my FTP connection setup:
$ftp = Storage::createFtpDriver([
'host' => $streamServer->url,
'username' => $streamServer->username,
'password' => $streamServer->password,
'port' => '21',
'timeout' => '30',
]);
Welcome to Stackoverflow
I have checked with my code and it's working when I added the following line in my filesystems.php
I have created ftp driver in filesystems as below.
'ftp' => [
'driver' => env('DOCUMENT_UPLOAD_DRIVER','sftp'),
'host' => env('DOCUMENT_UPLOAD_HOST','127.0.0.1'),
'username' => env('DOCUMENT_UPLOAD_USERNAME','root'),
'password' => env('DOCUMENT_UPLOAD_PASSWORD','root'),
'root'=> env('DOCUMENT_UPLOAD_ROOT', '/var/www/html')
'port' => env('DOCUMENT_UPLOAD_PORT', 22),
'timeout' => env('DOCUMENT_UPLOAD_TIMEOUT', 30),
],
this line is additionaly added.
'root'=> env('DOCUMENT_UPLOAD_ROOT', '/var/www/html')
and when I use the following command it works for me.
Storage::disk('ftp')->allDirectories('directoryName');
provide directory name from which you want to get list or leave blank will provide you the list of all the recursive directories from html directory because we have provided it as a root.
after that you need to extract directories manually, as it just gives you an array like namespace will all the recursive directories.
Do I need to have my DB connection info in 2 places? If I do the below, I connect just fine. If I remove either file's data, I can't connect.
config/databases.php file
'blah_1' => [
'driver' => 'mysql',
'host' => env('DB_HOST’,’1.1.1.1’),
'port' => env('DB_PORT','3306'),
'database' => env('DB_DATABASE’,’someDB_1’),
'username' => env('DB_USERNAME’,’someUser_1’),
'password' => env('DB_PASSWORD’,’somePass_1’),
],
'blah_2' => [
'driver' => 'mysql',
'host' => env('DB_HOST_SECOND’,’2.2.2.2’),
'port' => env('DB_PORT_SECOND','3306'),
'database' => env('DB_DATABASE_SECOND’,’someDB_2’),
'username' => env('DB_USERNAME_SECOND’,’someUser_2’),
'password' => env('DB_PASSWORD_SECOND’,’somePass_2’),
],
.env file:
DB_CONNECTION=blah_1
DB_HOST=1.1.1.1
DB_PORT=3306
DB_DATABASE=someDB_1
DB_USERNAME=someUser_1
DB_PASSWORD=somePass_1
DB_CONNECTION_SECOND=blah_2
DB_HOST_SECOND=2.2.2.2
DB_PORT_SECOND=3306
DB_DATABASE_SECOND=someDB_2
DB_USERNAME_SECOND=someUser_2
DB_PASSWORD_SECOND=somePass_2
The short answer is no. You only need it in your config/databases.php. The .env file is to overwrite the settings in your other environments without updating the configuration file.
For example, in your local environment, your credentials is most likely different from your production environment. You wouldn't want to update config/databases.php locally and remind yourself to not push the file.
However, the connections would still work even if remove them from the .env file. It will use the second parameter's value in your env() as default.
I am developing a laravel 5 project and storing image files using imagine. I would want to store my image files in a folder outside the project's root folder. I am stuck at the moment The external folder where image files are supposed to be stored, I want to make it accessible via a sub-domain something like http://cdn.example.com Looking towards your solutions.
The laravel documentation could give you a helping hand.
Otherwise you could go to config/filesystems.php and add your own custom storage path for both local and production:
return [
'default' => 'custom',
'cloud' => 's3',
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path().'/app',
],
'custom' => [
'driver' => 'custom',
'root' => '../path/to/your/new/storage/folder',
],
's3' => [
'driver' => 's3',
'key' => 'your-key',
'secret' => 'your-secret',
'region' => 'your-region',
'bucket' => 'your-bucket',
],
'rackspace' => [
'driver' => 'rackspace',
'username' => 'your-username',
'key' => 'your-key',
'container' => 'your-container',
'endpoint' => 'https://identity.api.rackspacecloud.com/v2.0/',
'region' => 'IAD',
],
],
];
get ur path name from base_path(); function, then from the string add your desired folder location.
suppose ur
base_path() = '/home/user/user-folder/your-laravel-project-folder/'
So ur desired path should be like this
$path = '/home/user/user-folder/your-target-folder/'.$imageName;
make sure u have the writing and reading permission
You can move all or a part of storage folder in any folder of yours in your server. You must put a link from old to new folder.
ln -s new_fodler_path older_folder_path
You can make a new virtual host to serve the new folder path.