简体   繁体   中英

File storeas not working on laravel project when deployed

I have laravel project that works on my localhost server, but when i deploy it on my 000webhostapp.com webhost domain. the file storeas is not working. it saves data but the file or image is not. heres the links. https://vincetestsite.000webhostapp.com/products_list

you can login by username - vince and password - 123

and the codes below.

    $product_name = $form->input('product_name');
    $description = $form->input('description');
    $pro_price = $form->input('pro_price');

    $product_id = DB::table('products_tbl')->insertGetId([  'product_name' => $product_name,
                                                            'description' => $description,
                                                            'pro_price' => $pro_price]);

    if($form->file('imgfile')){
        $imgfile = $form->file('imgfile');
        $imgfile->storeAs('public/storage/products', $product_id.'.jpg');
    }

Seems your code trying to put file in symbolic folder, which is not correct. You maybe just don't need to know what it is for now.

First, run this command: php artisan storage:link

Second, change your code:

$relPathAndName = $file->storePubliclyAs('/public/products', $product_id.'.jpg');

return str_replace('public', 'storage', $relPathAndName);

//Then to use it later: 
asset('storage/products/product_id.jpg')

As laravel instructions, you should store data under /path/to/yourproject/storage/app/public . Then once you a file or folder get created inside this folder, it will be automatically appear in /path/to/yourproject/public/storage

You can read more at: https://laravel.com/docs/5.4/filesystem

See screen shot to see how symlink works: http://image.prntscr.com/image/b4cfcf25b317471493855a49199f82d2.png

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM