Welcome Guest, Not a member yet? Register   Sign In
Upload a file to directory and Use Download Helper and Email Helper. ~Need Help!
#1

[eluser]Unknown[/eluser]
I have a file uploading system that have multiple function.

The system need to have this function:
1.) Upload a multiple files and save the encrypted name, file_path and original name to the DB.
2.) Download function for each file for that specific user with encrypted link like this http://localhost/projectWish/index.php/g...cf3c91e86e
3.) an email will send a encrypted link so that other users can download the file.
4.) And have a download link that can active for specific time only. ex: The user can download the file only for 5 days and after that the link will expire.

What I finish:
1.) I can already upload multiple files to the directory, but without saving the name and encrypted file name to the DB.

View template (gallery.php):

Code:
<body>
    <div id="gallery">

    </div>
    &lt;?php echo $error;?&gt;
    <div id="upload">
        &lt;?php
            echo form_open_multipart('gallery/file_upload');
            // echo "&lt;input type='file' name='files[]'/&gt;&lt;br/>";
            // echo "&lt;input type='file' name='files[]'/&gt;&lt;br/>";
            echo "&lt;input type='file' name='files[]' multiple/&gt;&lt;br/>";
            echo form_submit('upload', 'Upload');
            echo form_close();
        ?&gt;
    </div>
&lt;/body&gt;


Upload part of the controller(gallery.php):

Code:
function file_upload(){
        $this->gallery_path = realpath(APPPATH . '../files');
        $config = array(
            'allowed_types' => '*',
            'upload_path' => $this->gallery_path,
            'encrypt_name'  => true
        );
        $this->load->library('upload', $config);

        if($this->upload->do_multi_upload('files')){
            $upload_data = $this->upload->get_multi_upload_data();
            // print_r($this->upload->get_multi_upload_data());
            var_dump($upload_data);
            $this->load->view('gallery/upload_success', $upload_data);
        }
        else{
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('gallery/gallery', $error);
        }
    }


upload_success.php(view template):

Code:
&lt;body&gt;
        <h3>Your file was successfully uploaded!</h3>
        <ul>
            &lt;?php
            foreach ($upload_data as $item => $file):
                echo "<li>" . $file . "|" . $item . "</li>";
            endforeach;
            ?&gt;
        </ul>
        <p>&lt;?php echo anchor('gallery', 'Upload Another File!'); ?&gt;</p>
&lt;/body&gt;

-but I don't know how to use do_multi_upload() method and pass the values to the view templates. can someone teach me how to do this?

btw, I'm using this to upload multiple file in CI. https://github.com/stvnthomas/CodeIgniter-Multi-Upload
I have a code of basic email helper in CI, but I don't know how to make it dynamic so I can attach a multiple link of files to the message of the email. Can someone help or guide me in correct way. Haha. Thank you very much!
#2

[eluser]EyeAmN8[/eluser]
I did this a while ago so I'm just going off of memory. In your model (or wherever) check the post to see if it is an array, then loop through it. Inside your loop you can do the db inserts or build up another formatted array to insert into the db / change file names...




Theme © iAndrew 2016 - Forum software by © MyBB