help with directory included in string?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wmguk
Forum Newbie
Posts: 16
Joined: Wed Jan 30, 2008 6:16 am

help with directory included in string?

Post by wmguk »

hey guys,

I am using a thumbnail script and it gets the images from a directory, the images are found in ../../clients/$dir but i dont want to show the directory structure, in the images name so how can i specify the directory with out making the structure part of the name?

Code: Select all

 
    $dir = $_GET['login'];
    $pricing = $_GET['pricing'];
$NBFile=0;
$dir ="../../clients/$dir";
if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
        //if (substr($file, strlen($file)-3, 3)=="jpg" ) {
            $FileArray[] = $dir."/".$file;
            $NBFile=$NBFile+1;
        //}
 
        }
    }
}
closedir($handle);
 
 
any ideas?

Cheers
Drew
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: help with directory included in string?

Post by aceconcepts »

If you're using a database to reference the image and directory then you could simply specify an id.
wmguk
Forum Newbie
Posts: 16
Joined: Wed Jan 30, 2008 6:16 am

Re: help with directory included in string?

Post by wmguk »

no, what it is, its a thumbnail generator, looking at a directory on my server then showing those images, when i click on the images, it opens up to a biugger image,

everything works, its just that the image name becomes ../../clients/trial/image001.jpg and im hoping to get just image001.jpg

the images are in a folder called trial, ($login)
but the script is obviously in a totally different folder
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: help with directory included in string?

Post by aceconcepts »

If you are able to edit the thumbnail generator source code you shuld be able to edit the "name" assigned to the image.

So basically you should be able to extract just the images name from the entire path.

Do you have access to the thumbnail generator source code?
wmguk
Forum Newbie
Posts: 16
Joined: Wed Jan 30, 2008 6:16 am

Re: help with directory included in string?

Post by wmguk »

aceconcepts wrote:If you are able to edit the thumbnail generator source code you shuld be able to edit the "name" assigned to the image.

So basically you should be able to extract just the images name from the entire path.

Do you have access to the thumbnail generator source code?

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
    $dir = $_GET['login'];
    $pricing = $_GET['pricing'];
$NBFile=0;
$dir ="../../clients/$dir";
if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
        //if (substr($file, strlen($file)-3, 3)=="jpg" ) {
            $FileArray[] = $dir."/".$file;
            $NBFile=$NBFile+1;
        //}
 
        }
    }
}
closedir($handle);
?><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
.image{
    border-style:outset;
    border-color: black;
    border-width:1px;
      }
</style>
</head>
<body><table align="center"><tr>
<?php
$NBPicswidth=1;
$NBPics=0;
for ($i=0; $i<$NBFile; $i++) {
$Pic_Name1=$FileArray[$i];
?><td class="image">
  <a href="dis.php?image=<?php echo $Pic_Name1; ?>&pricing=<?php echo $pricing; ?>" target="order"><img src="<?php echo $Pic_Name1; ?>" width="100" border="0" align="top"></a>
</td></tr><?php
$NBPics=$NBPics+1;
 
if ( $NBPics==$NBPicswidth ) { $NBPics=0; ?>
<?php }
}
?></table>
</body>
</html>
 
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: help with directory included in string?

Post by aceconcepts »

Ok, I see your conundrum now.

What you could do is setup a "handler" in dis.php.

What I mean by "handler" is a few lines of code that appends the file name only i.e. image1.gif to a preset path.

Here's an example:

Code: Select all

<a href="dis.php?image=<?php echo $Pic_Name1; ?>&pricing=<?php echo $pricing; ?>" target="order"><img src="<?php echo $Pic_Name1; ?>" width="100" border="0" align="top"></a>
From the link above you will send $Pic_Name1 (which is just the file name - not the path) in the url.

Next, in dis.php retrieve the image:

Code: Select all

 
//SET THE CORRECT PATH FOR THE IMAGE DIRECTORY
   $dir="/your/image/path/";
 
if(isset($_REQUEST['image']) && !empty($_REQUEST['image']))
{
   //CRTEATE THE FULL PATH
      $fullPath=$dir . $_REQUEST['image'];
 
   //DISPLAY THE IMAGE
      echo'<img src=" ' . $fullPath . '" />';
}
 
You're oviously going to want to structure this a bit better but it gives you some idea hopefully.
wmguk
Forum Newbie
Posts: 16
Joined: Wed Jan 30, 2008 6:16 am

Re: help with directory included in string?

Post by wmguk »

Ok, i added this to the dis.php page however it still shows the file structure in the name, i cant work out how to use your code, becuase the script below self generated the thumbnails by checking the folder and then displaying how ever many images are in there

Code: Select all

 
    $dir = $_GET['login'];
    $pricing = $_GET['pricing'];
$NBFile=0;
$dir ="../../clients/$dir";
if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
        //if (substr($file, strlen($file)-3, 3)=="jpg" ) {
            $FileArray[] = $dir."/".$file;
            $NBFile=$NBFile+1;
        //}
 
        }
    }
}
closedir($handle);
 
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: help with directory included in string?

Post by aceconcepts »

If the code you displayed self generates then I dont think there is much you can do with the file name/path.
wmguk
Forum Newbie
Posts: 16
Joined: Wed Jan 30, 2008 6:16 am

Re: help with directory included in string?

Post by wmguk »

SOLVED IT

Code: Select all

 
    $dir = $_GET['login'];
    $pricing = $_GET['pricing'];
    $NBFile=0;
    $dir ="../../clients/$dir";
    
if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
        [b]$name = $file;[/b]
           $FileArray[] = $dir."/".$file;
            $NBFile=$NBFile+1;
        }
    }
}
closedir($handle);
Then

Code: Select all

 
  <a href="dis.php?image=<?php echo $Pic_Name1; ?>&pricing=<?php echo $pricing; [b]?>&name=<?php echo $name; ?>[/b]" target="order"><img src="<?php echo $Pic_Name1; ?>" width="100" border="0" align="top"></a>
 
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: help with directory included in string?

Post by aceconcepts »

Superb - well done!
wmguk
Forum Newbie
Posts: 16
Joined: Wed Jan 30, 2008 6:16 am

Re: help with directory included in string?

Post by wmguk »

oh nightmare :(

didnt work, it only keeps the first image name, and justt uses that, it doesnt actually read all the image names?

is there a way to do this with arrays?
Post Reply