0

Using Laravel 5.5, I have a method in my controller to get files from 1 folder, rename them and store them in my application and make them publicly accessible.

The method:

public function cleanup_files()
    {
        ini_set('max_execution_time', 3000);
        ini_set('memory_limit','16M');

        $i = 0;

        $files = Storage::disk('partE')->files('sb');

        foreach ($files as $file) {

        // strip the file name to about 20 characters and
        // then remove anything but numbers
        // since some of the names contain dates at the end.
            $digits =  preg_replace('/\D/', '', substr($file, 0, 20));

        // The remaining number contains 4 digits for the year 
        // and 1 to 4 digits for the number
            $year = substr($digits, 0, 4);
            $number = substr($digits, 4);

        // Now set the new filename
            $filename = 'SB' . $year . '-NO' . $number . '.pdf';

            if (! Storage::disk('public')->exists('sb/' . $filename)) {
                $newfile = new File(env('BULK_FILES_DIR') . $file);

                Storage::disk('public')->putFileAs('sb', $newfile, $filename);

                echo "New file added: " . $filename . '<br>';

                $i++;
            } else {

                echo $filename . " already exists in forlder.<br>";
            }
        }

        echo "<br><br>" . $i . " files added...";
    }

in my .env file on Windows I have BULK_FILES_DIR="D:/Projects/SBs/". On Ubuntu: BULK_FILES_DIR="/home/user/bibvault/"

in 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',
        ],

        'partE' => [
            'driver' => 'local',
            'root'   => env('BULK_FILES_DIR'),
        ]

    ],

This works nicely in Windows. Then I transfer it to my production machine, which is Ubuntu 16.04...

I created a DFS Windows share, added a special user, mounted this share: sudo mount -v -t cifs //doman.org/bibvault /home/user/bibvault -o uid=www-data,gid=www-data,credentials=/home/user/.cifscreds,iocharset=utf8,file_mode=0777,dir_mode=0777,context="system_u:object_r:httpd_sys_content_t:s0"

The mount is successful, I can see the files in Ubuntu. But when I run my method, I get fopen(/home/user/bibvault/sb/2004 no 87.pdf): failed to open stream: Permission denied

Whoops shows me line 162 of /vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php, which is in the definition of the putFileAs method.

I tried using my own uid, I gave the connecting Windows user write, then full access to the windows share. Nothing seems to change this error.

I'm not seeing it, so I hope anyone can point me to where it might be wrong. Maybe permission settings on the Windows share. Maybe on the mount itself... I have no clue at the moment..

Stretsh
  • 193
  • 1
  • 12

0 Answers0