webminer07
webminer07

Reputation: 313

Uploadpath CodeIgniter

I have created an uploads folder in the CodeIgniter root, that accepts all the uploaded images from the form. Then the upload path is sent to the database. Later i retrieve all the information from the database in a view page. I am trying to get all the images to display on the view page that are uploaded, but the upload path is adding too much to the URL.

the upload config looks like this:

$config = array(
        'upload_path'   => './uploads/',
        'allowed_types' => 'gif|jpg|png',
        'max_size'  => '6000',
        'max_width' => '2068',
        'max_height'    => '1032',
        'encrypt_name'  => true,
);

and the view page looks like this:

                                             <tr>                
                                                 <td><img src="<?php echo $pet->filepath?          
                                                     >" alt="pet photo"></img><br/></td>
                                                    <td><?php echo $pet->pet_name?><br/>      
                   </td>
                                                    <td><?php echo $pet->species."      "; 
               ?></td>
                                                    <td><?php echo $pet->breed; ?></td>
                                                    <td><?php echo $pet->gender; ?></td>
                                                    <td><?php echo $pet->color; ?></td>
                                                    <td><?php echo $pet->comments; ?></td>


                                            </tr>

                                    <?php endforeach; ?>

when i check the image URL when i test the view it shows up as: CodeIgniter_2.1.0/CodeIgniter_2.1.0/index.php/upload/uploads/beagle.jpg

but it needs to be: CodeIgniter_2.1.0/CodeIgniter_2.1.0/uploads/beagle.jpg

does anyone know how to change this??

Upvotes: 3

Views: 112

Answers (1)

SuperTron
SuperTron

Reputation: 4233

There is an easy to follow tutorial here that explains how to create a URL rewrite that removes the index.php. You could edit it to be something like this (not tested):

RewriteEngine on
RewriteCond $1 !^CodeIgniter_2.1.0/CodeIgniter_2.1.0/(index\.php|uploads.*|robots\.txt).*$
RewriteRule ^(.*)$ ^CodeIgniter_2.1.0/CodeIgniter_2.1.0/index.php/$1 [L]

Then you should (again, not tested), be able to access the image at CodeIgniter_2.1.0/CodeIgniter_2.1.0/uploads/beagle.jpg

EDIT: woops, misunderstood the question, you want CodeIgniter_2.1.0/CodeIgniter_2.1.0/index.php/upload/uploads/beagle.jpg -> CodeIgniter_2.1.0/CodeIgniter_2.1.0/uploads/beagle.jpg right?

In that case, give this a shot:

RewriteEngine on
RewriteRule ^.*/index.php/upload/uploads(.*)$ /CodeIgniter_2.1.0/CodeIgniter_2.1.0/uploads$1 [L]

This says any url that contains /index.php/upload/uploads should redirect to /CodeIgniter_2.1.0/CodeIgniter_2.1.0/uploads/whatever

Upvotes: 1

Related Questions