Jump to content

[SOLVED] How do i make it ignore a prefix ?


jamesxg1

Recommended Posts

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.

Link to comment
Share on other sites

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);
}

?>

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

<?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 ?

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.