Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Need Help with php image gallery
Old 11-28-2007, 06:33 AM Need Help with php image gallery
bigmacman's Avatar
Novice Talker

Posts: 7
Trades: 0
I use the Micro Photo Gallery the script finds all .jpg files and creates thumbnails if there isn't one and links the thumbnail with the jpg file.

I will use this script on a site, and I don't want to upload the same gallery on the other site, I just want the script to read from the folder of my first site the files. The original script only reads from the folder that is in.

Here is the script:
Code:
<?php 
/************************************************* 
 * Micro Photo Gallery 
 * 
 * Version: 1.0 
 * Date: 2007-04-05 
 * 
 * Usage: 
 * Just copy these files into your image folder 
 * 
 ****************************************************/ 
 
 $columns     = 5; 
 $thmb_width  = 120; 
 $thmb_height = 80; 
 
function resizeImage($originalImage,$toWidth,$toHeight){ 
    
    // Get the original geometry and calculate scales 
    list($width, $height) = getimagesize($originalImage); 
    $xscale=$width/$toWidth; 
    $yscale=$height/$toHeight; 
    
    // Recalculate new size with default ratio 
    if ($yscale>$xscale){ 
        $new_width = round($width * (1/$yscale)); 
        $new_height = round($height * (1/$yscale)); 
    } 
    else { 
        $new_width = round($width * (1/$xscale)); 
        $new_height = round($height * (1/$xscale)); 
    } 
    // Resize the original image 
    $imageResized = imagecreatetruecolor($new_width, $new_height); 
    $imageTmp     = imagecreatefromjpeg ($originalImage); 
    imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height); 
 
    return $imageResized; 
} 
 
function generateThumbnails(){ 
   global $thmb_width,$thmb_height; 
    
   // Open the actual directory 
   if ($handle = opendir(".")) { 
      // Read all file from the actual directory 
      while ($file = readdir($handle))  { 
         // Check whether tha actual item is a valid file 
         if (is_file($file)){ 
            // Check whether the actual image is a thumbnail 
               if (strpos($file,'_th.jpg')){ 
                  $isThumb = true; 
               } else { 
                  $isThumb = false; 
               } 
             
               if (!$isThumb) { 
                  // Process the file string 
                  $dirName  = substr($file,0,strpos($file,basename($file))); 
                  if (strlen($dirName) < 1) $dirName = '.'; 
                  $fileName = basename($file); 
                  $fileMain = substr($fileName,0,strrpos($fileName,'.')); 
                  $extName  = substr($fileName,strrpos($fileName,'.'), 
                                 strlen($fileName)-strrpos($fileName,'.')); 
                  
                  // Check if the actual file is a jpeg image 
                  if (($extName == '.jpg') || ($extName == '.jpeg')){ 
                   $thmbFile = $dirName.'/'.$fileMain.'_th.jpg'; 
                   // If a thumbnail dosn't exists tahn create a new one 
                   if (!file_exists($thmbFile)){ 
                      imagejpeg(resizeImage($file,$thmb_width,$thmb_height),$thmbFile,80); 
                   } 
               } 
               } 
            } 
         } 
   } 
    
} 
 
function getNormalImage($file){ 
   $base = substr($file,0,strrpos($file,'_th.jpg')); 
   if (file_exists($base.'.jpg')) return $base.'.jpg'; 
   elseif (file_exists($base.'.jpeg')) return $base.'.jpeg'; 
   else return ""; 
} 
 
function displayPhotos(){ 
   global $columns; 
    
   generateThumbnails(); 
   $act = 0; 
   // Open the actual directory 
   if ($handle = opendir(".")) { 
      // Read all file from the actual directory 
      while ($file = readdir($handle))  { 
         // Check whether tha actual item is a valid file 
         if (is_file($file)){ 
            // Check whether the actual image is a thumbnail 
               if (strpos($file,'_th.jpg')){ 
               ++$act; 
               if ($act > $columns) { 
                  echo '</tr><tr><td class="photo"><a href="'.getNormalImage($file).'"><img src="'.$file.'" alt="'.$file.'"/>[/url]</td>';    
                  $act = 1; 
               } else { 
                  echo '<td class="photo"><a href="'.getNormalImage($file).'"><img src="'.$file.'" alt="'.$file.'"/>[/url]</td>';    
               } 
                   
               } 
            } 
      } 
   }    
} 
 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> 
<html> 
<head> 
   <title>Micro Photo Gallery</title> 
   <link href="style/style.css" rel="stylesheet" type="text/css" /> 
</head> 
<body> 
  <div id="main"> 
    <div class="caption">Micro Photo Gallery</div> 
      <table align="center"><tr>      
          <?php displayPhotos(); ?> 
      </table>       
           
   <div id="source">Micro Photo Gallery 1.0</div> 
  </div> 
</body>
bigmacman is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-28-2007, 07:10 AM Re: Need Help with php image gallery
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I don't think that you can do what you want with this script.
It's based on a mechanism that scan the current directory structure.

URL access to a file is a completely different mechanism and cannot be implemented transparently at that level.
What you could do, is map a network drive through a VPN, and use that network drive as a source.

But in the end, I strongly discourage you of doing that.
It's just not worth the troubles...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-28-2007, 08:54 PM Re: Need Help with php image gallery
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
Is your site on your same server and do you have access to that site's directory over your FTP connection?
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 11-29-2007, 09:22 AM Re: Need Help with php image gallery
bigmacman's Avatar
Novice Talker

Posts: 7
Trades: 0
My new website isn't on the same server as the old
bigmacman is offline
Reply With Quote
View Public Profile
 
Old 11-29-2007, 12:18 PM Re: Need Help with php image gallery
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
As long as the directory can be accessed through FTP without a password it can be done. http://us3.php.net/function.opendir so in other words if you can connect to ftp://your.domain.com/images without using a password then you can use this script, otherwise it's not possible.
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 11-29-2007, 05:48 PM Re: Need Help with php image gallery
bigmacman's Avatar
Novice Talker

Posts: 7
Trades: 0
To have access throw ftp I have to insert my password. This script doesn't do the job, I was thinking of a script that searches the page for the thumbnails and the link to that image
Code:
<a href="http://domain.com/images/path/1.jpg"> 
<img src="http://domain.com/images/path/1_th.jpg"></a>
the script searches the page finds the link and puts in my page.

Another problem is the link, the link lucks like images/path/1.jpg the script will have to change it to "http://domain.com/images/path/1.jpg"
bigmacman is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Need Help with php image gallery
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22744 seconds with 12 queries