Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AhimbisibweRoland's avatar

Uploading files no a non laravel public directory

I am currently running a college project developed in laravel on shared hosting planning . I managed to upload user avatars to the storage directory and created symbolic link which works pretty nice on the local server but fails on the production server! How best do I make this work on a shared host?

0 likes
6 replies
jlrdw's avatar

Something like this:

    public function add()
    {
        if (isset($_POST['submit'])) {
            $lid = DB::table('dogs')->count();
            $lid = $lid + 1;
            $file = Input::file('ufile');
            $file_name = $file->getClientOriginalName();
            $file_ext = $file->getClientOriginalExtension();

            $fileInfo = pathinfo($file_name);
            $filename = $fileInfo['filename'];
            $newname = $filename . $lid . "." . $file_ext;
            $destinationPath = ROOTDIR . 'upload/imgdogs/';
            //Input::file('ufile')->move($destinationPath, $newname);
            $file->move($destinationPath, $newname);


            $dogpic = Cln::fixValue($newname);
            $dogname = ucfirst(Cln::fixValue($_POST['dogname']));
            $sex = ucfirst($_POST['sex']);
            $comments = Cln::fixValue($_POST['comments']);
            $adopted = (isset($_POST['adopted']) == '1' ? '1' : '0'); ///added
            $lastedit = date("Y-m-d H:i:s");
            echo "adpt=" . $adopted . "aaa";

            if (!isset($error)) {
                $postdata = array(
                    'dogpic' => $dogpic,
                    'dogname' => $dogname,
                    'sex' => $sex,
                    'comments' => $comments,
                    'adopted' => $adopted,
                    'lastedit' => $lastedit
                );

                DB::table('dogs')->insert($postdata);
            }
        }

        $this->layout = 'addtpl';
        return View::make('Dogs/Add')->shares('title', 'Dog Add');

    }

Done in a different framework, but symphony components, so very similar. Just set the destination path replace ROOTDIR with laravel usage.

AhimbisibweRoland's avatar

Thanks for the quick reply. I have everything working well on the local server. I am uploading the files to the the storage path using filesystems and creating a symbolic link between thr storage path and the public path But because i'm using a shared hosting which has a slight different structure than laravel , ie (public_html outside the laravel root directory), uploaded images are not being rendered by the browser. Thanks once again

jlrdw's avatar

I use godaddy shared hosting for a humane society site, and images display fine. Check folder permissions. On godaddy I did not have to change anything, I just ftp'ed laravel project, and it works, main files are above public_html. I put images under public.

AhimbisibweRoland's avatar

Ok. I will have to. Only that am putting mine under storage/app/public and then using a symbolic link

jlrdw's avatar

Can you share how you are doing the symbolic link?

Please or to participate in this conversation.