jgravois's avatar

Moving an Uploaded .pdf

I am trying to move an uploaded file to a file store using

public function store(Request $request)
    {
        $slug = str_slug($request->title);
        $request->request->add(['slug' => $slug]);

        if($request->hasFile('pdf')){
            $pdf_doc = $request->file('pdf');
            $pdf_title = $slug . '.pdf';
            $request->request->add(['pdf' => $pdf_title]);

            //TODO: save to FILE_STORE
            $pdf_doc->move(Config::get('filestore.path') . 'releases/', $pdf_title);
        } // end if

        $record = Release::create($request->all());
        return redirect()->action('WebsterController@press_releases');
    }

and I get this error

Could not move the file "/Applications/MAMP/tmp/php/phpmTUCJ7" to "/Users/jgravois/Documents/Code/_work/file_store/releases/my-upload-is-online.pdf" (PHP Startup: Unable to load dynamic library '/Applications/MAMP/bin/php/php7.0.10/lib/php/extensions/no-debug-non-zts-20151012/redis.so' - dlopen(/Applications/MAMP/bin/php/php7.0.10/lib/php/extensions/no-debug-non-zts-20151012/redis.so, 9): image not found)

It's a .pdf and not an image so "image not found" worries me.

I am just storing an upload so I don't understand what dynamic library (which seems to be missing) is needed

0 likes
4 replies
jcorry's avatar
jcorry
Best Answer
Level 1

I am just storing an upload so I don't understand what dynamic library (which seems to be missing) is needed

PHP is configured to load the library redis.so when it starts. It can't find the redis.so extension at the specified path.

I don't think 'image not found' is referring to your PDF file, but to the missing library (but I can't find specific references to that error's documentation).

I think the best approach would be to sort out your PHP configuration and make sure the server installation works as it's supposed to, then shift focus to your application code (which looks like it should work).

jgravois's avatar

@jcorry , you were absolutely correct ... the error was unrelated to what I was trying to do.

I still have one issue that I can't seem to solve ...

With these line, I am expecting the field 'pdf' to look something like 'an-aardvark-adventure.pdf' but instead, '/Applications/MAMP/tmp/php/phpZULZfF' is being saved to the database

    $pdf_title = $slug . '.pdf';
        $request->request->add(['pdf' => $pdf_title]);
jgravois's avatar

I figured it out ... naming the file input and the database field the same was too much for my code to bear. By changing the file input name, everything works fine

jcorry's avatar

I don't really love the way you're passing the entire request to your DB create method...that seems a little risky.

The behavior you're describing and the code on the screen above don't really line up (to me anyway)...

You can get the file's original name with $request->file('pdf')->getClientOriginalName(), maybe that would help?

Please or to participate in this conversation.