ctaljaardt's avatar

Filesystem Problems

Hello

I have a problem, im trying to upload a file to amazon s3 and im having a problem with the filesystem. i have set up the settings in the config with my information. and ive pulled in the composer package.

Here is a sample of my code

    public function uploadfile(Request $request,  $category)
    {
        $file = Input::file('file');
        $originalname = Input::file('file')->getClientOriginalName();
        $newname = str_random(32);
        $password = str_random(20);
        $newpath = storage_path("temp/");
        $extension = Input::file('file')->getClientOriginalExtension();
        $move = Input::file('file')->move($newpath, $originalname);
        shell_exec('7z a -p' . $password . ' -r ' . $newpath . $newname . '.7z ' . $newpath . $originalname);
        Storage::disk('s3')->put('/downloads/' . $category . '/' . $newname . ".7z", file_get_contents($newpath . $newname . '.7z'));
    }

Here is the error message im getting http://cl.ly/image/3q060P2J2Q0M

Here is a copy of my composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.1.*",
        "graham-campbell/markdown": "~3.0",
        "illuminate/html": "5.*",
        "aws/aws-sdk-php": "^3.0@dev"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-root-package-install": [
            "php -r \"copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}
0 likes
6 replies
mstnorris's avatar
Level 55

@ctaljaardt Check your namespaces because apparently League\Flysystem\AwsS3v3\AwsS3Adapter doesn't exist.

Have you imported it at the top of your file? Please show the full file that you gave us an excerpt of above.

masterakado's avatar

+1 @mstnorris Laravel 5, 5.1 changed to a namespaced container approach. You always have to define a namespace for your classes and you have to include this namespace to pull the class in other parts of your application.

Try something use League\Flysystem\AwsS3v3\AwsS3Adapter at the top of your file before your class and after you declare the namespace of the specific file you are editing at the time.

Also make sure the directory you are trying to upload your files already exists. I think laravel cannot create directories. It's going to search for a predefined directory and if this directory is not found then it will throw an exception.

ctaljaardt's avatar

@mstnorris Yeah, it was a stupid mistake, i copied and pasted what you wrote and it worked.

Thanks a lot for all your help :)

Please or to participate in this conversation.