Jump to content

Recommended Posts

I have the following code in index.php:

...
<table width="30%" border="0" cellpadding="7" cellspacing="5"><tr>
<td><a href="http://localhost/image.php?view=1"><img src="/images/image(1).JPG" width=200 height=170/></a></td>
<td><a href="http://localhost/image.php?view=2"><img src="/images/image(2).JPG" width=200 height=170/></a>></td>
<td><a href="http://localhost/image.php?view=3"><img src="/images/image(3).JPG" width=200 height=170/></a></td>
</tr>
</table>
...

 

where users chooses which image want to see in bigger size using page image.php:

<?php

$view1= $_GET['view'];

 if ($view1 == 1)
{
echo '<img src="/images/image(1).JPG" WIDTH=500 HEIGHT=400/>';
}
elseif ($view1 == 2)
{
echo '<img src="/images/image(2).JPG" WIDTH=500 HEIGHT=400/>';
}
else
{
echo '<img src="/images/image(3).JPG" WIDTH=500 HEIGHT=400/>';
}

?>

but photos do not load. Can anyone figure out what's going wrong? Thanks

Link to comment
https://forums.phpfreaks.com/topic/269533-select-image-to-enlarge/
Share on other sites

Well, you should definitely rethink the process, but the problem is that your parameter name is "view"

<td><a href="http://localhost/ima...hp?view=1"><img src="/images/image(1).JPG" width=200 height=170/></a></td> 

But, in your processing code you are checking "view1"

if ($view1 == 1) 

images_list.php (a file to define all the available images and the image directory)

<?php

$imageDir = '/images/';

$images = array(
   '1' => 'image(1).JPG',
  '2' => 'image(2).JPG',
  '3' => 'image(3).JPG'
);
?>

 

index.php (dynamically create the links based upon the defined images)

<?php
include(images_list.php);

echo "<table width='30%' border='0' cellpadding='7' cellspacing='5'>\n";
echo "<tr>\n";

foreach($images as $imageID => $imageName)
{
 echo "<td><a href='http://localhost/image.php?view={$imageID}'><img src='{$imageDir}{$imageName}' width='200' height='170' /></a></td>\n";
}
echo "</tr>\n";
echo "</table>\n";

?>

 

image.php (dynamically show the image comparing to the images list)

<?php
include(images_list.php);

$imageID = isset($_GET['view']) ? intval($_GET['view']) : false;

if($imageID===false || !in_arraY($imageID, $images))
{
  echo "No image selected!";
}
else
{
$imageName = $images[$imageID];
echo "<img src='{$imageDir}{$imageName}' WIDTH='500' HEIGHT='400' />n\";
}
?>

 

Note that using full size images as previews is a based idea as it still requires the user to download the full images. You should instead create smaller versions of the full size images and use those in the previews. Using the process above you could just create a subfolder (e.g. 'thumbs') and put the smaller images in there. They should have the same name as the full-size. Then, just change the index.php page to use the subfolder when creating the previews.

Edited by Psycho

Describe "photos don't load." In the first page? In the second? Does the HTML work? Black image? Broken image?

 

Your have invalid HTML in your index page, there's a >> that shouldn't be there.

 

The first page (index.php) loads fine. The problem is that in second page images don't load (i don't get a broken image icon just a white page). I have tried to change ' or " symbols in case the problem is there but nothing happened.

I think Psycho code works fine (at image.php />n\"; must be />\n" ; but i am trying to change a page that a friend made with a tool that generated the code. Because it has many tables and tags in it i guess there should be the problem (view source code ends before i put my php code). Thanks for your answers anyway!

Edited by free_man

I'd use rawurlencode () on those filenames, if I were you. I suspect it might help. That is, if you are 100% certain that the files are correctly named, including upper-lower case differences, and stored in the images/ folder of your web root.

 

Also, you state that "view source" ends before you put your PHP code. Should that be "put in" or "where I put"? In either case it suggests that you have a problem prior to the code you've pasted, or you're talking about something else. Showing us the results would go a long way in clearing up the confusion, and letting us know exactly what's going on.

i did tested your work in my localhost and it works.

 

try my revise code

 

test.php

 

<table width="30%" border="0" cellpadding="7" cellspacing="5"><tr>
<td><a href="test2.php?view=1"><img src="spike.jpg" width=102 height=147/></a></td>
</tr>
</table>

 

test2.php

 

<?php
$view1= $_GET['view'];
	 if ($view1 == 1)
{
echo '<img src="spike.jpg" WIDTH=500 HEIGHT=400/>';
}
elseif ($view1 == 2)
{
echo '<img src="spike2.jpg" WIDTH=500 HEIGHT=400/>';
}
else
{
echo '<img src="spike3.jpg" WIDTH=500 HEIGHT=400/>';
}
?>

Edited by JohnTipperton
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.