jamesxg1 Posted April 2, 2009 Share Posted April 2, 2009 This is complicated so i will explain in as much detail as i can, Ok what i need to do is make a php page display and image with the following link, PhotoView?image=UNIQE IMAGE ID HERE! and and lets say for instance the ID was 123456, That means that in the images/ folder there is a image called 123456 but i want to be able to put that url in a img src and not have to worry about prefix's i either need the PhotoView to auto get the prefix or to ignore it and not need it to display the picture. Is this possible ? Many many thanks, James. Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/ Share on other sites More sharing options...
Yesideez Posted April 2, 2009 Share Posted April 2, 2009 It's possible - you'd need to use fopen() to try and open each file in a loop recording which one it found (.gif, .jpg, .jpeg, .png etc.) then append the extension to the filename then place that inside IMG. http://uk.php.net/fopen Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799283 Share on other sites More sharing options...
jamesxg1 Posted April 2, 2009 Author Share Posted April 2, 2009 It's possible - you'd need to use fopen() to try and open each file in a loop recording which one it found (.gif, .jpg, .jpeg, .png etc.) then append the extension to the filename then place that inside IMG. http://uk.php.net/fopen Ok a little confussed, but heres the only thing i could come up with <?php $usid = mysql_real_escape_string(trim(intval($_GET['memberid']))); $search = @fopen("images/", "r"); if ($search) { while (!feof($search)) { $buffer = fgets($search, $usid); echo $buffer; } fclose($search); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799286 Share on other sites More sharing options...
Yesideez Posted April 2, 2009 Share Posted April 2, 2009 Something similar... $arrFileTypes=array('gif','jpg','jpeg','png'); foreach ($arrFileTypes as $type) { if ($fh=fopen($picname.$type,"r")) { $found=$type; close($fh); } } Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799289 Share on other sites More sharing options...
jamesxg1 Posted April 2, 2009 Author Share Posted April 2, 2009 Something similar... $arrFileTypes=array('gif','jpg','jpeg','png'); foreach ($arrFileTypes as $type) { if ($fh=fopen($picname.$type,"r")) { $found=$type; close($fh); } } Ok, but where would i put the folder for it to search ? Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799292 Share on other sites More sharing options...
jamesxg1 Posted April 2, 2009 Author Share Posted April 2, 2009 <?php $picname = mysql_real_escape_string(trim(intval($_GET['memberid']))); $arrFileTypes=array('gif','jpg','jpeg','png'); foreach ($arrFileTypes as $type) { if ($fh=fopen($picname.$type,"r")) { $found=$type; close($fh); } } ?> am i correct with this ? Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799295 Share on other sites More sharing options...
jamesxg1 Posted April 2, 2009 Author Share Posted April 2, 2009 ok i got it working except one thing :S Warning: fopen(1gif) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\social\PhotoView.php on line 7 Warning: fopen(1jpg) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\social\PhotoView.php on line 7 Warning: fopen(1jpeg) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\social\PhotoView.php on line 7 Warning: fopen(1png) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\social\PhotoView.php on line 7 it seems there is no "." between the name and prefix :S how do i do this ? Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799297 Share on other sites More sharing options...
jamesxg1 Posted April 2, 2009 Author Share Posted April 2, 2009 ok i got it working except one thing :S Warning: fopen(1gif) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\social\PhotoView.php on line 7 Warning: fopen(1jpg) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\social\PhotoView.php on line 7 Warning: fopen(1jpeg) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\social\PhotoView.php on line 7 Warning: fopen(1png) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\social\PhotoView.php on line 7 it seems there is no "." between the name and prefix :S how do i do this ? Please someone help. Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799304 Share on other sites More sharing options...
Yesideez Posted April 2, 2009 Share Posted April 2, 2009 if ($fh=fopen($picname.'.'.$type,"r")) { Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799307 Share on other sites More sharing options...
Yesideez Posted April 2, 2009 Share Posted April 2, 2009 As for where to put the folder... if ($fh=fopen('images/'.$picname.'.'.$type,"r")) { Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799308 Share on other sites More sharing options...
jamesxg1 Posted April 2, 2009 Author Share Posted April 2, 2009 As for where to put the folder... if ($fh=fopen('images/'.$picname.'.'.$type,"r")) { ok iv done the following and here's the result Warning: fopen(images/1.gif) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\social\ProfilePhoto.php on line 21 Warning: fopen(images/1.jpg) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\social\ProfilePhoto.php on line 21 Warning: fopen(images/1.jpeg) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\social\ProfilePhoto.php on line 21 Fatal error: Call to undefined function close() in C:\xampp\htdocs\social\ProfilePhoto.php on line 23 the image i am trying to get is in the directory and is a PNGG i can see the error for finding the PNG file is gone but it still isnt displaying anything :S Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799314 Share on other sites More sharing options...
Yesideez Posted April 2, 2009 Share Posted April 2, 2009 I don't know where your images are stored - all that is saying is that fopen() cannot find them. images/ is obviously the wrong folder - you'll have to change images/ to where your images are kept. Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799320 Share on other sites More sharing options...
gaza165 Posted April 2, 2009 Share Posted April 2, 2009 It cannot find the images... check your directory structure and check that it is looking in the correct place for the images. Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799322 Share on other sites More sharing options...
jamesxg1 Posted April 2, 2009 Author Share Posted April 2, 2009 I don't know where your images are stored - all that is saying is that fopen() cannot find them. images/ is obviously the wrong folder - you'll have to change images/ to where your images are kept. i have a folder named images with the follwing (Got this from CMD) Directory of C:\xampp\htdocs\social 02/04/2009 11:24 <DIR> . 02/04/2009 11:24 <DIR> .. 30/03/2009 15:22 <DIR> admin 02/04/2009 09:49 <DIR> css 23/05/2007 02:40 <DIR> db 30/03/2009 15:22 5,074 EditInfo.php 30/03/2009 15:22 5,243 EditPassword.php 01/04/2009 10:56 1,627 Functions.php 02/04/2009 11:26 <DIR> images 02/04/2009 11:30 5,818 Index.php 01/04/2009 18:28 <DIR> js 01/04/2009 21:27 4,781 Login.php 28/03/2009 20:03 728 Logout.php 30/03/2009 15:22 5,108 LostPassword.php 02/04/2009 09:14 1,739 PostComment.php 02/04/2009 10:25 5,248 Profile.php 02/04/2009 11:30 478 ProfilePhoto.php 30/03/2009 15:22 1,484 Register.php 01/04/2009 11:13 4,756 SaveUser.php 02/04/2009 09:59 3,411 ViewAllComments.php 13 File(s) 45,495 bytes 7 Dir(s) 37,172,310,016 bytes free C:\xampp\htdocs\social>cd /images C:\xampp\htdocs\social\images>dir Volume in drive C has no label. Volume Serial Number is D0D5-566F Directory of C:\xampp\htdocs\social\images 02/04/2009 11:26 <DIR> . 02/04/2009 11:26 <DIR> .. 15/02/2007 00:34 1,319 1.PNG 02/04/2009 09:17 4,863 apply.gif 05/06/2008 11:13 3,403 bak_09.png 15/02/2007 00:34 3,735 continue.png 15/02/2007 00:34 1,613 exclam.PNG 15/02/2007 00:34 204 index.php 15/02/2007 00:34 1,319 not.PNG 15/02/2007 00:34 55,598 pop.png 15/02/2007 00:34 1,525 suc.PNG 15/02/2007 00:34 19,405 works.png 10 File(s) 92,984 bytes 2 Dir(s) 37,172,310,016 bytes free C:\xampp\htdocs\social\images> Thats my folder structure and the image is in there as the image i am looking for is a .PNG file and when i go to view it that are every other prefix error except .PNG but when i view something else that prefix error goes aswell :S Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799325 Share on other sites More sharing options...
jamesxg1 Posted April 2, 2009 Author Share Posted April 2, 2009 i also put this * ProfilePhoto.php?memberid=bak_09 * in a image src and it didnt work :S Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799337 Share on other sites More sharing options...
Yesideez Posted April 2, 2009 Share Posted April 2, 2009 LOL my bad!!! Noticed it was a warning and not an error!!! if ($fh=@fopen('images/'.$picname.'.'.$type,"r")) { The "@" suppresses the error - use with caution when using this as you can hide valid error messages if used incorrectly. In this instance it's OK because we know this WILL definitely fail at some point. Just remember the "@" is there so if you experience problems in the future you can remove it for testing. Now just make sure you have files in the images/ folder for it to detect! Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799364 Share on other sites More sharing options...
jamesxg1 Posted April 2, 2009 Author Share Posted April 2, 2009 LOL my bad!!! Noticed it was a warning and not an error!!! if ($fh=@fopen('images/'.$picname.'.'.$type,"r")) { The "@" suppresses the error - use with caution when using this as you can hide valid error messages if used incorrectly. In this instance it's OK because we know this WILL definitely fail at some point. Just remember the "@" is there so if you experience problems in the future you can remove it for testing. Now just make sure you have files in the images/ folder for it to detect! lol, sorted all except for this. . . . Fatal error: Call to undefined function close() in C:\xampp\htdocs\social\ProfilePhoto.php on line 23 Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799396 Share on other sites More sharing options...
jamesxg1 Posted April 2, 2009 Author Share Posted April 2, 2009 sorted its suppost to be fclose() not close() lol Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799399 Share on other sites More sharing options...
jamesxg1 Posted April 2, 2009 Author Share Posted April 2, 2009 but not the script is error free i need to address the issue of. . . i cant display the images Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799401 Share on other sites More sharing options...
jamesxg1 Posted April 2, 2009 Author Share Posted April 2, 2009 does anyone know how i can do this ? Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799416 Share on other sites More sharing options...
Yesideez Posted April 2, 2009 Share Posted April 2, 2009 Does it actually come up with a success on finding any of the images? If it does - you know the folder the images are stored in, the name of the file and its extension. Just ECHO out the HTML to link to the image or if you want to be really eager use GD library functions to make the image and display it to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799421 Share on other sites More sharing options...
jamesxg1 Posted April 2, 2009 Author Share Posted April 2, 2009 Does it actually come up with a success on finding any of the images? If it does - you know the folder the images are stored in, the name of the file and its extension. Just ECHO out the HTML to link to the image or if you want to be really eager use GD library functions to make the image and display it to the browser. no, the image on the url is PhotoProcess.php?memberid=bak_09 but it is not displaying it at all it just has the browsers default "not found" image :S Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799425 Share on other sites More sharing options...
jamesxg1 Posted April 2, 2009 Author Share Posted April 2, 2009 <img src="PhotoProcess.php?memberid=bak_09" alt="picture" width="253" height="163"> is the code i have Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799426 Share on other sites More sharing options...
jamesxg1 Posted April 2, 2009 Author Share Posted April 2, 2009 is it something i am doing wrong ? Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799441 Share on other sites More sharing options...
Yesideez Posted April 2, 2009 Share Posted April 2, 2009 Just after $found=type add this line: echo 'FOUND:'.$type; Quote Link to comment https://forums.phpfreaks.com/topic/152206-solved-how-do-i-make-it-ignore-a-prefix/#findComment-799442 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.