Centre & Size Images (PHP)

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Centre & Size Images (PHP)

Post by D Willett »

Hi
I have some code to pull images and show in a frame within the browser.
I would like to centre the image selected and set the width and height.
The code is PHP.
I'm new to web programming so be gentle please.

Code: Select all

<?php
 error_reporting(0);
 ?>
<?PHP
  function getFileList($dir)
  {
    // array to hold return value
    $retval = array();

    // add trailing slash if missing
    if(substr($dir, -1) != "/") $dir .= "/";

    // open pointer to directory and read list of files
    $d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
    while(false !== ($entry = $d->read())) {
      // skip hidden files
      if($entry[0] == ".") continue;
      if(is_dir("$dir$entry")) {
        $retval[] = array(
          "name" => "$dir$entry/",
          "type" => filetype("$dir$entry"),
          "size" => 0,
          "lastmod" => filemtime("$dir$entry")
        );
      } elseif(is_readable("$dir$entry")) {
        $retval[] = array(
          "name" => "$dir$entry",
          "size" => filesize("$dir$entry"),
          "lastmod" => filemtime("$dir$entry")
        );
      }
    }
    $d->close();

    return $retval;
  }
?>
<?PHP
  $dirlist = getFileList(".");


  // output file list as HTML table

  echo "<table border=\"1\"> \n";
  echo "<tr><th>All Documents To View</th></tr>\n";
 

  foreach($dirlist as $file) {
if(!preg_match("/\.pdf$/", $file['name'])) continue;
    echo "<tr>\n";
    echo "<td><a href=\"{$file['name']}\" target=\"inner\">{$file['name']}</a></td>\n";
    echo "</tr>\n";
  }
  echo "</table><br>";
?>

<?php
//path to directory to scan. i have included a wildcard for a subdirectory

$directory = "";
 

//get all image files with a .jpg extension.

$images = glob("" . $directory . "*.jpg");


$imgs = '';

// create array

foreach($images as $image){ $imgs[] = "$image"; }


//shuffle array

shuffle($imgs);


//select first 12 images in randomized array

$imgs = array_slice($imgs, 0, 150);


//display images

foreach ($imgs as $img) {
    echo "<a href=\"$img\" target=\"inner\"><img src='$img' width=\"80\" border=\"1\"/></a> ";


}
?>
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Centre & Size Images (PHP)

Post by HansV »

You're becoming too smart for us, Dave! :grin: I don't think we've had PHP questions here yet...
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Centre & Size Images (PHP)

Post by D Willett »

I wish !!!!!!!!!!

You know my mind never stops exporing lol >>

I'm playing about with web pages now, you'll see alot of my latest questions incorporated, ie csv, ftp etc etc.
My VB software now uploads to the web, it's a long way off but I'll get there.

"url removed"

You can search job numbers ( any advice helps too ):-)

201211
201371
201397

Just examples.
Last edited by D Willett on 30 May 2012, 14:29, edited 1 time in total.
Cheers ...

Dave.

User avatar
stuck
Panoramic Lounger
Posts: 8127
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: Centre & Size Images (PHP)

Post by stuck »

Off topic but an observation on the speed at which your web page loads if I search for the first job number - it's slow. I could see some of the thumbnails loading a line at a time.

Also is it wise to have the car reg numbers publicly visible like this?

Ken

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Centre & Size Images (PHP)

Post by D Willett »

Hi Ken

Points noted
I originally set the images to show 12 as opposed to 150 as it is now. Part of the development will be to paginate the image set.
It's very early days yet so I have lots of things to do.
If someone can take the PHP code and improve it and add paginate that would save me loads of time ( I know, I'm too demanding sometimes ) lol.
Registration Numbers: This will be a restricted site and only people with authorisation will have access, mainly Insurers so it's not too much of an issue.

But, thanks for the comments, the more the better.

Kind Regards
Cheers ...

Dave.

User avatar
stuck
Panoramic Lounger
Posts: 8127
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: Centre & Size Images (PHP)

Post by stuck »

D Willett wrote:This will be a restricted site and only people with authorisation will have access
I thought so but my point was that it's not restricted at the moment and now that you've posted the link here what's on there at the moment is now public knowledge. I realise the chances of a bad guy finding this link and then harvesting these few reg. nos. for underhand reasons is low but would the owners of the cars would see it that way?

Ken

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Centre & Size Images (PHP)

Post by D Willett »

Hi Ken
There's no more information on there than anyone can access by noting registrations walking along a street.
Insurers are stringent on security and don't give information out without first grilling the person asking the questions.

I'll be more carefu next time, your advice is welcome.

Regards
Cheers ...

Dave.

User avatar
stuck
Panoramic Lounger
Posts: 8127
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: Centre & Size Images (PHP)

Post by stuck »

D Willet wrote:There's no more information on there than anyone can access by noting registrations walking along a street.
Umm, yes, you're right hadn't thought of it that way. Sorry, I was going in to overdrive :pun:

Ken

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Centre & Size Images (PHP)

Post by D Willett »

No probs.

Still haven't found a way to centre and resize though Lol..........
Cheers ...

Dave.

User avatar
Jezza
5StarLounger
Posts: 847
Joined: 24 Jan 2010, 06:35
Location: A Magic Forest in Deepest, Darkest, Kent

Re: Centre & Size Images (PHP)

Post by Jezza »

D Willett wrote:No probs.

Still haven't found a way to centre and resize though Lol..........
Hi Dave

Sorry air code here but have you tried to change line 88 of your code to this:

Code: Select all

echo "<a href=\"$img\" target=\"inner\"><img src='$img' width=\"50%\" height=\"50%\" align=\"middle\"/></a> ";
I have set the image to be set at 50% of width and height placing in the centre horizontally
Jerry
I’ll be more enthusiastic about encouraging thinking outside the box when there’s evidence of any thinking going on inside it

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Centre & Size Images (PHP)

Post by D Willett »

Hi Jerry
I tried your version, worked on the left frame but not in the main view frame.
There seems to be some kind of event fired on selection of the thumb image which then appears in the centre frame.
As I didn't write most of the code it's difficult to trap where this event fires.
If I could step throught the code I could trap what's happening ??
These are the files which may point to what I'm trying to achieve:

Index.php (path: public_html/Image_Client)

Code: Select all

<?php
$jobno = $_POST["jobno"];
echo "<frameset rows=\"60,*,80\"><frame name=\"top\" src=\"search.php\" />
<frameset cols=\"17%,*\">
   <frame name=\"console\" src=\"$jobno/console.php\" />
   <frame name=\"inner\" src=\"inner.htm\" />
 </frameset> 
   <frame name=\"bottom\" src=\"$jobno/inner.php\" />
</frameset>";
?>
Inner.htm (path: public_html/Image_Client)

Code: Select all

<html>
<body>
<p align="center">Welcome to the On-Line Version of MIC-Console.
Select an Image or Document of Your Choice From the Left.</p>
<BR><BR>
<p align="center"><IMG SRC ="mainimage.png" border = "1" body></p>
</html>
Search.php (path: public_html/Image_Client)

Code: Select all

<html>
<head></head>
<body>
<body style="background-color:#7A67EE">
<form action="index.php" method="POST" enctype="multipart/form-data" target="_parent">
<input name="jobno" value="Job Number" type="text">
<input type="submit" value="search">
</form>
</body></html>
And in the search directories:(path:public_html/Image_Client/201211)

Code: Select all

<?php
 error_reporting(0);
 ?>
<?PHP
  function getFileList($dir)
  {
    // array to hold return value
    $retval = array();

    // add trailing slash if missing
    if(substr($dir, -1) != "/") $dir .= "/";

    // open pointer to directory and read list of files
    $d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
    while(false !== ($entry = $d->read())) {
      // skip hidden files
      if($entry[0] == ".") continue;
      if(is_dir("$dir$entry")) {
        $retval[] = array(
          "name" => "$dir$entry/",
          "type" => filetype("$dir$entry"),
          "size" => 0,
          "lastmod" => filemtime("$dir$entry")
        );
      } elseif(is_readable("$dir$entry")) {
        $retval[] = array(
          "name" => "$dir$entry",
          "size" => filesize("$dir$entry"),
          "lastmod" => filemtime("$dir$entry")
        );
      }
    }
    $d->close();

    return $retval;
  }
?>
<?PHP
  $dirlist = getFileList(".");

  // output file list as HTML table

  echo "<table border=\"1\"> \n";
  echo "<tr><th>. Available Documents .</th></tr>\n";
  //echo "<tr><th>All Documents To View</th></tr>\n";

  foreach($dirlist as $file) {
if(!preg_match("/\.pdf$/", $file['name'])) continue;
    echo "<tr>\n";
    echo "<td><a href=\"{$file['name']}\" target=\"inner\">{$file['name']}</a></td>\n";
    echo "</tr>\n";
  }
  echo "</table><br>";
?>

<?php
//path to directory to scan. i have included a wildcard for a subdirectory

$directory = "";
//get all image files with a .jpg extension.

$images = glob("" . $directory . "*.jpg");

$imgs = '';

// create array

foreach($images as $image){ $imgs[] = "$image"; }

//shuffle array

shuffle($imgs);

//select first 150 images in randomized array

$imgs = array_slice($imgs, 0, 150);

//display images

foreach ($imgs as $img) {
    echo "<a href=\"$img\" target=\"inner\"><img src='$img' width=\"80\" border=\"1\"/></a> ";

}
?>
Inner.php(path:public_html/Image_Client/201211)

Code: Select all

<?php
 error_reporting(0);
 ?>
<?php 
echo "<html><body><center><font face=\"arial\"><table border=\"1\">\n\n"; 
$f = fopen("cdata.csv", "r"); 
while (($line = fgetcsv($f)) !== false) { 
        echo "<tr>"; 
        foreach ($line as $cell) { 
                echo "<td><font size=1>" . htmlspecialchars($cell) . "</font></td>"; 
        } 
        echo "<tr>\n"; 
} 
fclose($f); 
echo "\n</table><center></body></html>"; 
Perhaps the answer is within, I just can't see it?
Cheers ...

Dave.