Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOtherTutorials

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old December 16th, 2003, 01:35 PM
HriBB HriBB is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Slovenia
Posts: 15 HriBB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Notepad's image gallery+GD

SYSTEM: winxp, easyphp (apace 1.3, php 4.3.3, mysql 4.xxx)

ME: beginner

php Code:
Original - php Code
  1.  
  2. function display_body($navtree)
  3. {
  4.     if(isset($GLOBALS['nav']))
  5.     {
  6.         for($i=1; $i<count($GLOBALS['crunch']); $i++)
  7.         $uri .= !is_numeric($GLOBALS['crunch'][$i]) ? $GLOBALS['crunch'][$i].'/' : '';
  8.     }
  9.  
  10.     if(is_array($navtree))
  11.     {
  12.         if(!is_numeric(implode('', array_keys($navtree))))
  13.         {
  14.             print('<tr><td>');
  15.             foreach($navtree as $key=>$value)
  16.             {
  17.                 if(!is_int($key))
  18.                 {
  19.                     if(is_array($value))
  20.                         print('<a href="'.$_SERVER['PHP_SELF']
  21.                         .'?nav='.rawurlencode($GLOBALS['nav']
  22.                         .'>'.$key).'">'.$key.'</a><br />');
  23.                     else
  24.                         print($key.'<br />');
  25.                 }
  26.             }
  27.         print('</td></tr>');
  28.     }
  29.     else
  30.     {
  31.         $total = count($navtree);
  32.         if(isset($GLOBALS['viewall']))
  33.         {
  34.             $check = $total / COLS;
  35.             $rows = is_int($check) ? $check : floor($check) + 1;
  36.         }
  37.         else
  38.             $rows = ROWS;
  39.  
  40.             navigator($total);
  41.             for($i=0; $i<$rows; $i++)
  42.             {
  43.                 print('<tr>');
  44.                 for($n=0; $n<COLS; $n++)
  45.                 {
  46.                     $index = $GLOBALS['start']++;
  47.                     $image = $index < $total ? $navtree[$index] : '&nbsp;';
  48.                     print('<td align="center" width="'.THMBWIDTH.'" height="'.THMBHEIGHT.'">');
  49.                     if($image != '&nbsp;')
  50.                     {
  51.                         print('<a href="'.$_SERVER['PHP_SELF']
  52.                         .'?nav='.rawurlencode($GLOBALS['nav']
  53.                         .'>'.$index).'">');
  54.                         print('<img src="imgsrc.php?src='.PATH.rawurlencode
  55.                         ($uri).$image.'" border="0" />');
  56.                         print('</a>');
  57.                     }
  58.                             else
  59.                         print($image);
  60.                                 print('</td>');
  61.                 }
  62.                 print('</tr>');
  63.             }
  64.             navigator($total);
  65.         }
  66.     }
  67.     elseif(file_exists(PATH.$uri.$navtree))
  68.     {
  69.         $root = explode('/', dirname(PATH.'.'));
  70.         print('<tr><td><img src="'.end($root).'/'.$uri.$navtree.'"></td></tr>');
  71.     }
  72.     else
  73.         print('<tr><td>invalid request</td></tr>');
  74. }


Ok this is the same code which notepad used in his tutorial. I get this error message:
Notice: Undefined variable: uri in d:wwwimages.php on line 85

I notice a dot(.) before = ($uri .= !is_numeric...)
If I remove it (but this probably is not OK) the error is gone. But then when i click the thumbnail i get: invalid request (i knew it was not OK)

Please help me.

Reply With Quote
  #2  
Old December 16th, 2003, 03:02 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to notepad
RE: Notepad's image gallery+GD

it's just a notice, put an '@' before it:

@$uri .= etc..

kinda weird tho yah, of course it's an undefined variable.. that's why we're defining it

Reply With Quote
  #3  
Old December 16th, 2003, 09:14 PM
HriBB HriBB is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Slovenia
Posts: 15 HriBB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Notepad's image gallery+GD

what does the dot in front of = mean?

Reply With Quote
  #4  
Old December 16th, 2003, 09:42 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to notepad
RE: Notepad's image gallery+GD

it's a concatination, it means add onto the existing value rather than redefine the variable completely..

for example:
php Code:
Original - php Code
  1.  
  2. $uri = 'one';
  3. $uri = 'two';
  4. echo $uri; // prints two
  5.  
  6. $uri = 'one';
  7. $uri .= 'two';
  8. echo $uri; // prints onetwo
  9.  

Reply With Quote
  #5  
Old December 17th, 2003, 12:04 AM
HriBB HriBB is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Slovenia
Posts: 15 HriBB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Notepad's image gallery+GD

thanx 4 the explanations guys.
but now i have another problem. GD library won't display the thumbnails. I can open the images, but the thumbnails aren't there. GD library works fine, i tested it..
this code:
php Code:
Original - php Code
  1. <?php
  2.         header ("Content-type: image/png");
  3.         $img_handle = ImageCreate (230, 20) or die ("Cannot Create image");
  4.         $back_color = ImageColorAllocate ($img_handle, 0, 10, 10);
  5.         $txt_color = ImageColorAllocate ($img_handle, 233, 114, 191);
  6.         ImageString ($img_handle, 31, 5, 5"My first Program with GD", $txt_color);
  7.         ImagePng ($img_handle);
  8.     ?>

Outputs a black image saying: "My first Program with GD"
I updated php to 4.3.4, apache is v. 1.3 (i use easyphp), and i run winXP (is this the problem). I studied GD library tutorial and studied the code in both images.php and imgsrc.php carefully but i cant find the solution.

is there a problem in this line?
php Code:
Original - php Code
  1. print('<img src="imgsrc.php?src='.PATH.rawurlencode($uri).$image.'"


Notepad u said that .= adds a value to the variable $uri (which is at the time NULL, or am i wrong). So if the value is added how come there is and error undefined variable uri?

Sorry for asking so many questions, but i really want to finish this great script, which is BTW exactly what i need, and what i've been looking for for a month

here's the code:

IMAGES.PHP
php Code:
Original - php Code
  1. <?php
  2.  
  3. require_once('config.php');
  4.  
  5. $nav = isset($_REQUEST['nav']) ? urldecode($_REQUEST['nav']) : null;
  6. if(isset($nav))
  7. {
  8.     $crunch = explode('>', trim($nav));
  9.     foreach($crunch as $value)
  10.     {
  11.         if(!ctype_alnum(str_replace(' ', '', $value))) {
  12.         $invalid = true;
  13.     } else {
  14.         $invalid = false;
  15.         }
  16.     }
  17.     if($invalid)
  18.     $nav = null;
  19. }
  20.  
  21. $pg = isset($_REQUEST['pg']) && (ctype_digit($_REQUEST['pg']) ||
  22. $_REQUEST['pg'] == 'all') ? $_REQUEST['pg'] : 0;
  23. $viewall = is_numeric($pg) ? null : true;
  24. $pg = intval($pg) <= 0 ? 1 : $pg;
  25.  
  26. $section = ROWS * COLS;
  27. $end = $section * $pg;
  28. $start = $end - $section;
  29. $prev = $pg - 1;
  30. $next = $pg + 1;
  31.  
  32. print('<table border="0" align="center" cellpadding="1" cellspacing="1">');
  33.  
  34. function navigator($total)
  35. {
  36.     $p = '<a href="'.$_SERVER['PHP_SELF'].'?nav='.rawurlencode($GLOBALS['nav']).'&pg='.$GLOBALS['prev'].'"><<</a>';
  37.     $n = '<a href="'.$_SERVER['PHP_SELF'].'?nav='.rawurlencode($GLOBALS['nav']).'&pg='.$GLOBALS['next'].'">>></a>';
  38.     $a = '<a href="'.$_SERVER['PHP_SELF'].'?nav='.rawurlencode($GLOBALS['nav']).'&pg=all">viewall</a>';
  39.  
  40.     print('<tr><td align="center" colspan="' . COLS . '">');
  41.    
  42.     if(($GLOBALS['pg'] == 1 && $GLOBALS['end'] >= $total) || isset($GLOBALS['viewall']))
  43.         print('<< : view all : >>');
  44.     elseif($GLOBALS['pg'] == 1)
  45.         print('<< : '.$a.' : '.$n);
  46.     elseif($GLOBALS['end'] < $total)
  47.         print($p.' : '.$a.' : '.$n);
  48.     else
  49.         print($p.' : '.$a.' : >>');
  50.  
  51.     print('</td></tr>');
  52. }
  53.  
  54. function directory($dir)
  55. {
  56.     $mydir = opendir($dir);
  57.     while(false !== ($file = readdir($mydir)))
  58.     {
  59.     if($file != "." && $file != "..")
  60.     {
  61.         if(is_dir($dir.$file))
  62.         {
  63.             @chdir('.');
  64.             $tree[$file] = directory($dir.$file.'/');
  65.             @chdir('..');
  66.         }
  67.         else
  68.         {
  69.             $size = getimagesize($dir.$file);
  70.             if(in_array($size['mime'], unserialize(TYPE)))
  71.             $tree[] = $file;
  72.         }
  73.     }
  74.     }
  75.     closedir($mydir);
  76.     return $tree;
  77. }
  78. $tree = directory(PATH);
  79.  
  80. function display_body($navtree)
  81. {
  82.     if(isset($GLOBALS['nav']))
  83.     {
  84.         for($i=1; $i<count($GLOBALS['crunch']); $i++)
  85.         @$uri .= !is_numeric($GLOBALS['crunch'][$i]) ? $GLOBALS['crunch'][$i].'/' : '';
  86.     }
  87.  
  88.     if(is_array($navtree))
  89.     {
  90.         if(!is_numeric(implode('', array_keys($navtree))))
  91.         {
  92.             print('<tr><td>');
  93.             foreach($navtree as $key=>$value)
  94.             {
  95.                 if(!is_int($key))
  96.                 {
  97.                     if(is_array($value))
  98.                         print('<a href="'.$_SERVER['PHP_SELF']
  99.                         .'?nav='.rawurlencode($GLOBALS['nav']
  100.                         .'>'.$key).'">'.$key.'</a><br />');
  101.                     else
  102.                         print($key.'<br />');
  103.                 }
  104.             }
  105.         print('</td></tr>');
  106.     }
  107.     else
  108.     {
  109.         $total = count($navtree);
  110.         if(isset($GLOBALS['viewall']))
  111.         {
  112.             $check = $total / COLS;
  113.             $rows = is_int($check) ? $check : floor($check) + 1;
  114.         }
  115.         else
  116.             $rows = ROWS;
  117.  
  118.             navigator($total);
  119.             for($i=0; $i<$rows; $i++)
  120.             {
  121.                 print('<tr>');
  122.                 for($n=0; $n<COLS; $n++)
  123.                 {
  124.                     $index = $GLOBALS['start']++;
  125.                     $image = $index < $total ? $navtree[$index] : '&nbsp;';
  126.                     print('<td align="center" width="'.THMBWIDTH.'" height="'.THMBHEIGHT.'">');
  127.                     if($image != '&nbsp;')
  128.                     {
  129.                         print('<a href="'.$_SERVER['PHP_SELF']
  130.                         .'?nav='.rawurlencode($GLOBALS['nav']
  131.                         .'>'.$index).'">');
  132.                         print('<img src="imgsrc.php?src='.PATH.rawurlencode($uri).$image.'"                                 border="0" />');
  133.                         print('</a>');           
  134.                     }
  135.                             else
  136.                         print($image);
  137.                                 print('</td>');
  138.                 }
  139.                 print('</tr>');
  140.             }
  141.             navigator($total);
  142.         }
  143.     }
  144.     elseif(file_exists(PATH.$uri.$navtree))
  145.     {
  146.         $root = explode('/', dirname(PATH.'.'));
  147.         print('<tr><td><img src="'.end($root).'/'.$uri.$navtree.'"></td></tr>');
  148.     }
  149.     else
  150.         print('<tr><td>invalid request</td></tr>');
  151. }
  152.  
  153. function categories($navtree)
  154. {
  155.     if(isset($GLOBALS['nav']))
  156.     {
  157.         for($i=1; $i<count($GLOBALS['crunch']); $i++)
  158.         $navtree = &$navtree[$GLOBALS['crunch'][$i]];
  159.         display_body($navtree);
  160.     }
  161.     else
  162.         display_body($navtree);
  163. }
  164. categories($tree);
  165.  
  166. print('</table>');
  167.  
  168. ?>


IMGSRC.PHP
php Code:
Original - php Code
  1.  
  2. <?php
  3.  
  4. require_once('config.php');
  5.  
  6. $src = isset($_REQUEST['src']) ? urldecode($_REQUEST['src']) : null;
  7.  
  8. if(isset($src) && file_exists($src))
  9. {
  10.     header('Content-Type: image/jpg');
  11.  
  12.     list($width, $height, $type, $attr) = getimagesize($src);
  13.     $img = imagecreatefromjpeg($src);
  14.     $lowest = min(THMBWIDTH / $width, THMBHEIGHT / $height);
  15.  
  16.     if($lowest < 1)
  17.     {
  18.     $smallwidth = floor($lowest*$width);
  19.     $smallheight = floor($lowest*$height);
  20.     $tmp = imagecreatetruecolor($smallwidth, $smallheight);
  21.     imagecopyresized($tmp, $img, 0, 0, 0, 0, $smallwidth, $smallheight, $width, $height);
  22.     imagedestroy($img);
  23.     $img = $tmp;
  24.     }
  25.     imagejpeg($img, '', 100);
  26.     imagedestroy($img);
  27. }
  28.  
  29. ?>


CONFIG.PHP
php Code:
Original - php Code
  1.  
  2. <?PHP
  3. define('PATH', '/www/images/');
  4. define('TYPE', serialize(array('image/jpg', 'image/jpeg', 'image/pjpeg')));
  5. define('ROWS', 3);
  6. define('COLS', 5);
  7. define('THMBWIDTH', 100);
  8. define('THMBHEIGHT', 100);
  9. ?>   


Thanx for the answers in adwance

Bojan

Reply With Quote
  #6  
Old December 17th, 2003, 12:21 AM
HriBB HriBB is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Slovenia
Posts: 15 HriBB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Notepad's image gallery+GD

some more things
script is in the folder d:www
images are in the folder d:wwwimages(gallery)(image_x.jpg)

and here is the url:
http://hribo.kicks-***.net/images.php

should i set permissions CHMOD 777 on files

and how to enable error reporting?

Reply With Quote
  #7  
Old December 17th, 2003, 12:30 AM
Matt Matt is offline
Contributing User
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 12 m 16 sec
Reputation Power: 7
RE: Notepad's image gallery+GD

[Moved to tutorial forum]

Reply With Quote
  #8  
Old December 17th, 2003, 02:10 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to notepad
RE: Notepad's image gallery+GD

my script doesn't care for local addresses, it doesn't compensate for the colon i don't think.. someone else is having the same problem with a path similar to yours i'm kinda playin with it. i'll let you know

Reply With Quote
  #9  
Old December 17th, 2003, 05:05 PM
HriBB HriBB is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Slovenia
Posts: 15 HriBB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Notepad's image gallery+GD

ok...
d:/www/ is my root with all 3 scripts
/www/images/ here are the dirs with images

this is copy->paste from html view source.
<a href="/images.php?nav=%3Ekavka%3E0"><img src="imgsrc.php?src=/www/images/kavka%2Fslika001.jpg" border="0" /></a>

is the /www/ supposed to be there? this is the source of the large image, am i right?

and also there's an error: undefined variable $uri. is this the problem?

i just don't get it... it displays small pics with red x and when i click on any of them it opens picture normally. it just won't display thumbs. is there a possible error in imgsrc.php

GRRRRRR....

Reply With Quote
  #10  
Old December 17th, 2003, 05:43 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to notepad
RE: Notepad's image gallery+GD

put an @ symbol before the $uri line to get rid of the notice.. there's no problem in imgsrc.php, it just isn't being passed the right path. take a look at this thread for some possible fixes

Reply With Quote
  #11  
Old December 18th, 2003, 12:54 AM
HriBB HriBB is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Slovenia
Posts: 15 HriBB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Notepad's image gallery+GD

Still NOTHING!!!

DOCUMENT_ROOT = d:/www
SERVER_ADDR = 127.0.0.1

/www/gallery/all three scripts here in the same dir
/www/gallery/images/ dir pappa with pictures in .jpg format

large images are displayed normally, but not thumbs so there must be an error in line
php Code:
Original - php Code
  1. print('<img src="imgsrc.php?src='.PATH.rawurlencode($uri).$image.'" border="0" />');


what should the line
php Code:
Original - php Code
  1. <img src="imgsrc.php?src=
look like?
php Code:
Original - php Code
  1. <img src="/www/gallery/imgsrc.php?src=

or
php Code:
Original - php Code
  1. <img src="/gallery/imgsrc.php?src=

or just
php Code:
Original - php Code
  1. <img src="/www/gallery/imgsrc.php?src=


darn php!!!

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > Notepad's image gallery+GD


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek