saunders1989 Posted February 10, 2010 Share Posted February 10, 2010 im just trying to use the script i have to shrink down some images that are massive but for some reason i cant get it to work. when i click on a thumbnail which i use the script to create it redirects you to a page called image.php and that displays the image in its full size but i need to shrink it down a little. so far on my image.php file my code looks like this: <?php $dbLink = new mysqli('localhost', 'root', '', 'gallery'); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } if(isset($_GET['id']) && is_numeric($_GET['id'])) { /* $_GET['id'] passes our test, so perform security functions on it & assign it to the $id variable */ $id= $dbLink->real_escape_string($_GET['id']); } else { /* it doesn't exist or it isn't numeric so assign a default value so our query below always gets constructed properly & safely */ $id = 1; } /* construct the query */ $query = "SELECT name, size, image_path FROM images WHERE id = $id"; /* run the query */ $result = $dbLink->query($query); $maxheight=300; $maxwidth=250; $row = $result->fetch_row(); list($width, $height) = getimagesize($row[2]); if ($width > $maxwidth || $height > $maxheight) { echo "<img src=\"imageResize.php?imageFilename=" . $row[2] . "&maxHeight=" . $maxheight . "&maxWidth=" . $maxwidth . "\" />\n"; } else { echo "<img src=\"" . $row[2] . "\" />"; } ?> only problem is i get an error : Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in C:\wamp\www\Blean_Photos\image.php on line 70 and i dont understand how to fix it. if you need more explanation im glad to explain Thanks Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/ Share on other sites More sharing options...
jl5501 Posted February 10, 2010 Share Posted February 10, 2010 The first thing to do is find out what you are getting in $row by doing print_r($row); then you can find out why it is not as expected. for debug, you might also like to check your query worked by doing $result = $dbLink->query($query) or die(mysql_error().' '.$query); Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010270 Share on other sites More sharing options...
saunders1989 Posted February 10, 2010 Author Share Posted February 10, 2010 ive tried doing both of your methods but nothing changed it still shows that error and wont print anything. Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010295 Share on other sites More sharing options...
jl5501 Posted February 10, 2010 Share Posted February 10, 2010 Are you saying you get no output from the print_r() If that is true then you are close to your answer as you are not getting anything from the db Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010325 Share on other sites More sharing options...
saunders1989 Posted February 10, 2010 Author Share Posted February 10, 2010 when i do print_r($row) nothing appears but that same line error Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010327 Share on other sites More sharing options...
jl5501 Posted February 10, 2010 Share Posted February 10, 2010 so, that is the key to your whole problem If you are not getting an error from mysql_error and you are getting nothing from the query, then you are querying a row for an id that is not in the db Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010328 Share on other sites More sharing options...
sader Posted February 10, 2010 Share Posted February 10, 2010 does passing MYSQLI_STORE_RESULT help? $result = $dbLink->query($query, MYSQLI_STORE_RESULT); Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010329 Share on other sites More sharing options...
saunders1989 Posted February 10, 2010 Author Share Posted February 10, 2010 still this error - Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in C:\wamp\www\Blean_Photos\image.php on line 70 it doesnt like the variable $row Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010335 Share on other sites More sharing options...
sader Posted February 10, 2010 Share Posted February 10, 2010 I am not sure but maybe u get $row with named keys? so for example u shoud try use $row['image_path'] instead $row[2] and btw where u put print_r as jl5501 sugessted? u should put it after $row = $result->fetch_row(); $row = $result->fetch_row(); print_r($row); Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010339 Share on other sites More sharing options...
jl5501 Posted February 10, 2010 Share Posted February 10, 2010 if the class function fetch_row is akin to mysql_fetch_row, then it is being processed correctly. furthermore print_r is printing nothing suggesting that it is getting nothing There is probably a function akin to mysql_num_rows() that he can call which would further check Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010355 Share on other sites More sharing options...
saunders1989 Posted February 10, 2010 Author Share Posted February 10, 2010 i dont understand why when i put print_r($row) i still only shows that error message. which is really odd. here is how i use my imageResize script to create my thumbnails. while ($row = $result->fetch_assoc()) { echo "<a href=\"image.php?id=" . $row['id'] . "\">"; echo "<img src=\"imageResize.php?imageFilename=" . $row['name'] . "&maxHeight=120,&maxWidth=150\" />\n"; echo "</a>\n"; all i want to do is use that similiar method to just shrink down the large images to a easier size to view. Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010363 Share on other sites More sharing options...
jl5501 Posted February 10, 2010 Share Posted February 10, 2010 Your problem here is not the image manipulation, but that you are not getting any data out of the database Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010385 Share on other sites More sharing options...
sader Posted February 10, 2010 Share Posted February 10, 2010 how query looks if u print it like this. $query = "SELECT name, size, image_path FROM images WHERE id = $id"; echo "<code>".$query."</code>"; Is it correct? can u retrive any data with this query via phpmyadmin Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010397 Share on other sites More sharing options...
jl5501 Posted February 10, 2010 Share Posted February 10, 2010 well when the query actually runs it will have a value for $id. It seems that in your case, that whatever that value is, returns no row Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010406 Share on other sites More sharing options...
saunders1989 Posted February 10, 2010 Author Share Posted February 10, 2010 this is what i get when i echo the query: SELECT name, size, image_path FROM images WHERE id = 53 the 53 is cause ive had loads of images in my database and my incrementing number has risen up and starts at that number. is there not a way of changing this bitof code: while ($row = $result->fetch_assoc()) { echo "<a href=\"image.php?id=" . $row['id'] . "\">"; echo "<img src=\"imageResize.php?imageFilename=" . $row['name'] . "&maxHeight=120,&maxWidth=150\" />\n"; echo "</a>\n"; } so i can incoprate that into the image.php file which has only this at the moment: while($row = $result->fetch_row()) { echo "<img src=\"" . $row[2] . "\" />"; // you could also play with the other $row[] variables returned by the query here. } Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010455 Share on other sites More sharing options...
sader Posted February 11, 2010 Share Posted February 11, 2010 so u want to say that ID that u pass trought url is biger them increment key on the table and image with id=53 doesn't exists? Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010463 Share on other sites More sharing options...
saunders1989 Posted February 11, 2010 Author Share Posted February 11, 2010 i dont understand what your saying?. with the first bit of code it takes the thumbnail image and creates on on a page called image.php with that certain id. the next bit is the script i want to incorprate on image.php but dont know how Link to comment https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010726 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.