Welcome Guest, Not a member yet? Register   Sign In
[Solved] how to hide a part of url?
#1

[eluser]Mr-H[/eluser]
hi every body
i have a script that allow people to upload their pictures to the server and desplay the url like this : http//localhost/ci/uploads/my_pic.jpg
(the data of the image is stored in the db )
what i want to do is hide the uploads folder from the url so the script can be much more secure.
how can i do this whith out using htaccess file but the database.
#2

[eluser]echoDreamz[/eluser]
You could do http://localhost/ci/load/image/image_name and create the load controller with a method called image that takes 1 parameter.

Pull the data from the database using the image name, and return it to the browser. You would need to set the proper headers / MIME types to insure it is displayed properly.
#3

[eluser]Mr-H[/eluser]
yes that what i want to do ,but i dont know how ?
any explaination please.
#4

[eluser]pickupman[/eluser]
Here is one that I am using

Code:
<?php
class Imaging extends Controller {
    
    function Imaging()
    {
        parent::Controller();
    }
    
    function index($image = FALSE)
    {
        
        if($image)
        {
            $query = $this->db->get_where('gallery',array('gallery_id'=>$image));
            if($query->num_rows() > 0)
            {
                $imageArray = $query->row_array();
                $image = 'uploads/images/'.$imageArray['gallery_filename'];
            }
            
        
        
        $thumb = str_replace('.jpg','_thumb.jpg',$image);
        
        //Check for thumbnail
        if( !file_exists(BASEPATH.'../'.$thumb) ){
          
            //Load image maniuplation
            $config['dynamic_output'] = FALSE;
            $config['create_thumb'] = TRUE;
            $config['source_image'] = $image;
            $config['wm_type'] = 'overlay';
            $config['wm_overlay_path'] = $config['base_path'].'uploads/images/watermark.png';
            $config['wm_opacity'] = '80';
            $this->load->library('image_lib',$config);
            
            $this->image_lib->watermark();
        }
        
        header('Content-type: image/jpeg');
        echo file_get_contents($thumb);
        }
    }
}

I've created a more complicated one that handles many types of mime headers and checks user access. This is pretty simple to read what's going and adapt it to your needs. It basically takes a image id as a parameter, looks up the id in the DB, if id is found check for a thumbnail image, if not create one, and output thumbnail to user. In my code I have

Code:
<img src="&lt;?php echo site_url('imaging/index/123');?&gt;" alt="Some title" />

You could take it another step further and add a route like
Code:
$route['imaging/(:any)'] = 'imaging/index/$1';

Then just call like
Code:
site_url('imaging/123');
#5

[eluser]Mr-H[/eluser]
thank you pickupman but i have already create a thumb; and i dont wana dispaly the id in the url but a friendly url like this: http://localhost/link/my_pic
#6

[eluser]pickupman[/eluser]
[quote author="Mr-H" date="1274123387"]thank you pickupman but i have already create a thumb; and i dont wana dispaly the id in the url but a friendly url like this: http://localhost/link/my_pic[/quote]

Like I mentioned, the code is all right there just change it to suit your needs. Rather than retrieving a image id, alter the code to lookup up the image name. Change the name of the controller, or use a route to do it for you.

Code:
$route['link/(:any)'] = 'imaging/index/$1';

Use whatever way you want to get the filename from the DB, and use the part you really need is:

Code:
header('Content-type: image/jpeg');
echo file_get_contents($full_path_to_filename);
#7

[eluser]Mr-H[/eluser]
thanks pickupman ,i got it
but the thing is in the uri segment.
her is my code ,i wish that can help some body
Code:
function link($id)
    {

        if($id)
        {
            //initialise the uri
            $image = $this->uri->segment(3);
            $sub_folder = $this->uri->segment(4);
            $orig_name = $this->uri->segment(5);
            $query = $this->db->get_where('img_uploader',array('id'=>$image,'sub_folder' => $sub_folder ,'orig_name' =>$orig_name));
            //make sure if the image existe in db
            if($query->num_rows() > 0)
            {
                
                $imageArray = $query->row_array();
                $image ='uploads/'.$imageArray['sub_folder'].'/'.$imageArray['orig_name'];
                header('Content-type: image/jpeg');
                 echo file_get_contents($image);//.$imageArray['sub_folder'].'/'.$imageArray['orig_name']);

            }
            else{
                echo "You enter an invalide url ";
            }
        }
        else{
                echo " No image found";
            }
    }
my url looks like this : http://localhost/myscript/controller/link/12/skljd06/myfile.ext
12 is the id
skljd06 is the subfolder (for every file uploaded i create a folder with random name )
myfile.ext is the name of the file with extension
friendly url ;-)




Theme © iAndrew 2016 - Forum software by © MyBB