Welcome Guest, Not a member yet? Register   Sign In
file uploading
#1

Hello,

I am new to coding world and using CI4.4.6
I followed the manual about file uploading and I successfully made the link to force file downloaded via web browser.

One problem I encountered is the how can I link to the mp3 file.
I made <audio><source src=""></audio> but it didn't play the mp3 file. 

I researched and found some solution;
1. I have to move 'WRITEPATH . 'uploads/' directory to '/public' because /public directory is able to be accessed via web.

Here is a question. 
If my understanding is right, how can I change the directory from '/writable' to '/public' ?

Here is my code in Controller.

PHP Code:
$userfile $this->request->getFile('userfile');
WRITEPATH 'uploads/' $userfile->store(); 


even though tried below the result is same strangely. File is still stored in writable directory !!!!

PHP Code:
$userfile $this->request->getFile('userfile');
$filepath '/public/aaa' $userfile->store(); 
Reply
#2

Read https://codeigniter.com/user_guide/libra...tore-files

The following code is a bit difficult to understand, but $img->store() moves the file.

PHP Code:
        if (! $img->hasMoved()) {
            $filepath WRITEPATH 'uploads/' $img->store();

            $data = ['uploaded_fileinfo' => new File($filepath)];

            return view('upload_success'$data);
        
Reply
#3

According to my understanding, $file->store() is CI4's function which only works for WRITEPATH. With store(), I can only modify the folder under the WRITEPATH.

So I use $file->move() to save uploaded file and set the directory '/public' manually. After saving uploaded files in '/public', I can link mp3 file in audio tag.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB