The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

how to add an image in with other files?

Hello, I'm trying to get this code to show the images along with other files but it won't work. I tried adding an image tag and that didn't help, didn't know how to include an if statement if its a ".gif " or something. Can someone please tell me how to include an image in with the rest of these in the array? Thanks very much.

file_get_contents() literally sticks the contents of a file into the PHP code. It doesn't automatically wrap <img> tags around images or anything like that (which is required to display an image on an HTML page). Adding <img> tags to the array value (i.e. $allfiles[3] = '<img src="thatfile.gif" />') won't work either, not only because I didn't put a semi-colon (stupid winking smiley...) but also because PHP will try and find a file named <img src="thatfile.gif" /> (including the <img> tags etc.).

You'd have to use something simple like:

Code:

echo '<img src="' . $allfiles[3] . '" />';

And if that doesn't work... you must have your image path wrong or something, because it should work.

Explorer, thats exactly what I needed, thanks very much, didn't know how to do it. If I have more than 3 image files I can just then change the -3 to -4?

There is only one problem happening, the file echo works fine but if there is an image the image jumps out of the page and appears somewhere where it wants. It looks like it will only keep one echo in the page and not sure why. Any way to keep both echos inside a web page? Please let me know thanks a lot.

If I have more than 3 image files I can just then change the -3 to -4?

No, -3 tells substr to take 3 chars starting from right position from string (see: http://php.net/substr), thus in the code above, it gets the extension of file name supplied.

I'm not surely understand your 2nd question, but I guess it depends on surrounding html code for that page (if you inserting that php code in the middle of html code). Maybe if you can provide your url or if you don't want to show it to public you can pm me, so I can see what the real problem is.