• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
displaying images from a folder

#1
[eluser]learning_php[/eluser]
Hi,

I have created a file upload that puts the images into a folder but I am unsure how to get the images into an array and display them in rows.

Code:
<?PHP

class uploadimg extends Controller {
    
        
    function uploadimg()
    {
    
    parent::Controller();
    
    
    
    }
    
    function index(){
        $this->load->view('upload');
        
    }
    function do_upload()
    {
        // Image configuration
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['overwrite'] = FALSE;
        $config['max_size'] = 2048;
        
        $this->load->library('upload', $config);
        
    
        if(!$this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('upload', $error);
        }
        else
        {
            
        
            $image = $this->upload->data();
            $data['image'] = "./uploads/".$image['file_name'];
            
            $config['image_library'] = 'gd2';
            $config['source_image'] = $data['image'];
            $config['create_thumb'] = TRUE;
            $config['maintain_ratio'] = TRUE;
            $config['width'] = 150;
            $config['height'] = 150;
            $config['new_image'] = "./uploads/".$image['file_name'];
            
            $this->load->library('image_lib', $config);
            
            $this->image_lib->resize();
            
            $data = array('upload_data' => $this->upload->data());
            
            $this->load->view('upload_suc', $data);
            
        }
    }
}

#2
[eluser]TheFuzzy0ne[/eluser]
Is the more than one image? If so, we will probably need to see your implementation before we can make suggestions.

#3
[eluser]learning_php[/eluser]
Hi,

Yes there will be more than one file, my idea is that users can upload images into the folder then the thumbnails that get created also in the folder would be diplayed in rows and link to the full sized image also saved in the same folder?

Sorry i am not sure what you mean by implementation?

Thanks

#4
[eluser]Yorick Peterse[/eluser]
I had a function written for a gallery which would display all images in folder x, the function itself is pretty clumsy and could have been done way better, but it might be helpful.

Code:
function Category() {
        $URL_Title     = $_GET['title'];        
        
        if($URL_Title !== null) {
            //Check if the category folders that belong to the current title exist and fetch their contents
            $Full_Dir         = "gallery/normal/$URL_Title/";
            $Thumb_Dir        = "gallery/thumbs/$URL_Title/";
            //Scan directories
            if(file_exists($Full_Dir)) {
                $Scan_Full        = scandir($Full_Dir);
            }
            if(file_exists($Thumb_Dir)) {
                $Scan_Thumb        = scandir($Thumb_Dir);
            }
            echo "<div id=\"image-wrap\">";
            for($i = 0; $i<count($Scan_Thumb); $i++) {
                if($Scan_Thumb[$i] != "." && $Scan_Thumb[$i] != ".." && preg_match('/[.](jpg)|(gif)|(png)$/',$Scan_Thumb[$i])) {
                    $FullName = str_replace("thumb_","",$Scan_Thumb[$i]);
                    $ThumbLayout = <<<THUMBS
                    <div class="image-box">
                        <a href="$Full_Dir$FullName" title="$FullName" rel="lightbox[roadtrip]"><img src="$Thumb_Dir$Scan_Thumb[$i]" alt="$Scan_Thumb[$i]" /></a>
                    </div>
THUMBS;
                    echo $ThumbLayout;
                }                
            }
            echo "</div>";
        }
        else {
            echo "<h2>The page you requested does not exist!</h2>";
        }
        echo "</div>";
    }

In this case the "scandir()" function is the most important function:

http://nl2.php.net/scandir


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.