Jump to content
xisto Community
khalilov

Php And Showing Pics

Recommended Posts

I made a small script which creates a 10x10 picture out of small pictures

<html><body><?phpfor($j=0;$j<10;$j++)   {{for($i=0;$i<10;$i++)   echo "<img src=C:\wamp\www\Game\pic\grass.jpg>";   }   echo "<br>";   }?></body></html>
grass.jpg is a simple pic, anyways when i run it using wamp it shows 10x10 pics of nothing, as in the pics aren't loading. When i right click them and enter properties it says they are not available. I enter page source and find
<img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><br><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><br><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><br><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><br><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><br><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><br><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><br><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><br><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><br><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><img src=C:\wamp\www\Game\pic\grass.jpg><br></body>
Basicly its the code that shows the image 100 times, i copy and paste the code and save it as .html , the big pic shows normally. I save the php file as .html and when i open it i get
"; } echo ""; } ?>

I thought it had something to do with the loops so i modified it to simply
<html><body><?php   echo "<img src=C:\wamp\www\Game\pic\grass.jpg>";  ?></body></html>
Same result, a picture with not available source and grass.jpg is not viewing, how do i make them show? I tried in both firefox and IE.
How do i make pics work in php?

Edit: i noticed i got alot of mycents on this post i think, iam guessing this is from the 100 img viewing codes i posted, if it is considered spam or abuse, plz replace them with quotes =)
Edited by khalilov (see edit history)

Share this post


Link to post
Share on other sites

You're not using the img tag correctly.
It should be:

<img src="C:\wamp\www\Game\pic\grass.jpg" />

instead echo "<img src=C:\wamp\www\Game\pic\grass.jpg>" prints
<img src=C:\wamp\www\Game\pic\grass.jpg>
(without the quotes around the path).

Change your echo command into this and it should work:
echo '<img src="C:\wamp\www\Game\pic\grass.jpg" />'


btw. avoid using absolute paths, makes it incredibly hard to migrate your website.

Share this post


Link to post
Share on other sites

Still doesn't work :/, and what do you mean making it hard to migrate my website?

Edit: I saved it as .html and noticed that it works when i open it directly, but when i open it from localhost (LOCALHOST/game/x.html) it doesn't work.

Server Configuration
Apache Version :
2.2.8
PHP Version :
5.2.6

Thats the wamp version iam using.
Edited by khalilov (see edit history)

Share this post


Link to post
Share on other sites

Try adding file:// before the C:\wamp part.

 

At present your website is located in your localhost. Migrating it implies that you are moving it to a real host so that it can be accessed on, say, yourdomain.com. Suppose your index file is localhost/index.php and the pictures are located in the pic directory. Its best to use relative URLs such as <img src='/pic/grass.jpg' />. Now when you move your website to yourdomain.com, all you need to do is copy the files (PHP & Images) to your hosted account. In the current scenario, you will need to change the src attribute to <img src='http://yourdomain.com/pic/grass.jpg' /> when you move to yourdomain.com, <img src='http://forums.xisto.com/no_longer_exists/' /> if you are moving to khalilov.astahost.com, and so on.

 

Note: Remember that ./ refers to the current directory, .. the parent and / the root directory.

Share this post


Link to post
Share on other sites

It works thanks alot m8 :rolleyes:
I was just testing it thats why i put the direct link to the page =)
Btw when i open it in firefox there is a distance between the image. Iam assuming its default in firefox, but i want the pics to appear right next to each other like in IE, whats the CSS code to do so =), i tried

<table border=0 cellspacing=0><?php  for($j=0;$j<10;$j++)   {echo "<tr>"; for($i=0;$i<10;$i++)   {?>   <td><img src="file:\\C:\wamp\www\Game\pic\grass.jpg"></td>    <?php }  echo "</tr>";  }?></table>
The distance between the pics got smaller but it is still easily noticable.

Edit: its working in firefox but not in IE O.o,output page source is the same

Also can you tell me how to do the file link with :/pic/grass.jpg , file://pic/grass.jpg doesn't seem to work
Edited by khalilov (see edit history)

Share this post


Link to post
Share on other sites

I don't understand why are you creating links from windows environment for file:// ??? if you're using PHP why not use the normal http address? for example:

LOCALHOST/Game/pic/grass.jpg ???

you can get the full/absolute path in different ways, one way is to use $_SERVER; super global, just look the array value you need by doing:

echo '<pre>';print_r($_SERVER);echo '</pre>';exit;

and you'll see what you can get and what you can use with it.. If you ask me, never use the file:// path, if possible avoid using absolute path, the best method is just writing:

images/image.jpg and that in that html file the browser could find it, one way is to use ../ parent dir or ./ current dir or ../../ two parent directories:

../images/image.jpg it will take the image from a parent directory in that location if it's accessible :rolleyes:

Share this post


Link to post
Share on other sites

In the begining i wrote just parent and file and absolute path but neither showed the image :rolleyes:. The image was blocked for some reason. Read my first post and you'll understand =)

Share this post


Link to post
Share on other sites

You have always been using file path. Initially you were missing the quotations " around the value of the src attribute. I presume your page is located at LOCALHOST/Game/index.php. Its best that you use the img tag as <img src="/Game/pic/grass.jpg"> (relative to the root) or <img src="pic/grass.jpg"> (relative to the current page).

Share this post


Link to post
Share on other sites

you're doing something wrong or maybe you have some super cool anti spyware which does not let IE to view localhost content? or something like that, those kind of things works on all the browsers I know. :rolleyes:

Share this post


Link to post
Share on other sites

But how come they don't appear in IE :/

If you have an index.php file in your Game folder, you cannot see any files, with IE you can only start the index.php program.Just for fun, rename your index.php to index.something, rename your index.html to index.somethingelse and you will be able to see the files with IE6.

Share this post


Link to post
Share on other sites

But how come they don't appear in IE :/

Can you re-post your entire source code and the exact location of your files (PHP and Images). Also, what URL (including the hostname) you use to access the page. We have been assuming a lot of stuff on our own. It would be easier to help, if you provided all the details.

If you have an index.php file in your Game folder, you cannot see any files, with IE you can only start the index.php program.Just for fun, rename your index.php to index.something, rename your index.html to index.somethingelse and you will be able to see the files with IE6.


I don't think he is referring to the directory listing feature of Apache which works as the index page when there is none.

Share this post


Link to post
Share on other sites

If you have an index.php file in your Game folder, you cannot see any files, with IE you can only start the index.php program.Just for fun, rename your index.php to index.something, rename your index.html to index.somethingelse and you will be able to see the files with IE6.


Doesn't work


* {  margin: 0;  padding: 0;}a:link {  color: white; text-decoration: none; }a:visited {  color: green; text-decoration: none; } a:hover { color: orange; }.boldtable {position:relative;top:216px;left:250px;font-family:sans-serif;font-size:12pt;color:yellow;background-image: url(C:\wamp\www\Game\pic\grass.jpg); 	background-repeat: repeat;} .boldtable1 TD, .boldtable1 TH{font-family:sans-serif;font-size:8pt;width=74px;height:57px;color:yellow;}p.map{ position:relative;left:20%;top:20%;width:70%;height:70%;background-image: url(grass.jpg); 	background-repeat: repeat; }
<link rel="stylesheet" type="text/css" href="map.css" /><p class="map"><?php$x=$_GET['x'];$y=$_GET['y'];$x*=74;$y*=57;echo "<img style='position:relative;top:".$y."px;left:".$x."px;'src='file:\\C:\wamp\www\Game\pic\mark.jpg'>";?><?php /* <table  class=boldtable1 cellspacing=0><link rel="stylesheet" type="text/css" href="map.css" /><?php$x=$_GET['x'];$y=$_GET['y'];  for($j=0;$j<10;$j++)    {echo "<tr>"; for($i=0;$i<10;$i++)   {if(($i!=$x)||($j!=$y)){?>   <td>	<?php echo "<a href=map.php?x=".$i."&y=".$j.">"; ?>   	<img src="file:\\C:\wamp\www\Game\pic\grass.jpg"></a></td>    <?php }   else { ?>   <td><img src="file:\\C:\wamp\www\Game\pic\mark.jpg"></td>   <?php }}  echo "</tr>";  }</table>  */?></p>
C:\wamp\www\Game\pic\grass.jpg
C:\wamp\www\Game\pic\mark.jpg
Are the direct links to the pics, the grass (background) is appearing normally, mark isn't loading in IE, but its loading in Firefox.

Share this post


Link to post
Share on other sites

If you have an index.php file in your Game folder, you cannot see any files, with IE you can only start the index.php program.

Just for fun, rename your index.php to index.something, rename your index.html to index.something else and you will be able to see the files with IE6.


EDIT - Ha, I just read your quote again and understood that it wasn't the case, well I will still leave this post content, sorry.. :P

 

I don't think that it depends on IE or any browser.. something like that, if you access lets say Game/pic/ directory, all what you get depends on how apache or any other server will treat this request, if you'll set:

 

DirectoryIndex index.html index.php index.phtml

for that kind of request it will search for index.html first, if it won't find it it will search for index.php and so on, if it won't find anything when it will show directory listing, you can avoid it showing directory listing by using this command:

 

IndexIgnore *

with IndexIgnore you can make lots of things like I remember, make it show only images or the extension you'll set, can't remember..

 

for example you can create/write:

 

DirectoryIndex myindexfilename.myextensionname

and it will be the default file for the request, some older servers doesn't use index.html but instead still use default.html :rolleyes:
Edited by Quatrux (see edit history)

Share this post


Link to post
Share on other sites

Here it all works for me now:

map.css File:

* {  margin: 0;  padding: 0;}a:link {  color: white; text-decoration: none; }a:visited {  color: green; text-decoration: none; }a:hover { color: orange; }.boldtable{position:relative;top:216px;left:250px;font-family:sans-serif;font-size:12pt;color:yellow;background-image: url('http://localhost/Game/pic/grass.jpg');	background-repeat: repeat;}.boldtable1 TD, .boldtable1 TH{font-family:sans-serif;font-size:8pt;width:74px;height:57px;color:yellow;}p.map{ position:relative;left:20%;top:20%;width:70%;height:70%;background-image: url('Pic/grass.jpg');background-repeat: repeat; }

I prefer to use ' ' in css in an url() but they are not necessary and here is your index.php file a little bit fixed:

<link rel="stylesheet" type="text/css" href="map.css" /><p class="map"><?php$x=$_GET['x'];$y=$_GET['y'];$x*=74;$y*=57;echo '<img style="position:relative;top:'.$y.'px; left:'.$x.'px;" src="http://localhost/Game/pic/mark.jpg">';?><table'>http://localhost/Game/pic/mark.jpg">';?><table class="boldtable1" cellspacing="0"><link rel="stylesheet" type="text/css" href="map.css" /><?php$x=$_GET['x'];$y=$_GET['y'];  for($j=0;$j<10;$j++)   {echo '<tr>'; for($i=0;$i<10;$i++)   {if(($i!=$x)||($j!=$y)){?>   <td>	<?php echo '<a href="map.php?x='.$i.'&y='.$j.'">'; ?>	<img src="http://localhost/Game/pic/grass.jpg" /></a></td>  <?php }   else { ?>   <img src="http://localhost/Game/pic/mark.jpg" /></td>  <?php }}  echo '</tr>';  }?></table></p>

To give you a little bit of suggestion, try to stick to that when on PHP you're writing simple text, use ' ' and for parsing use " ", for example echo 'Hello world'."\n".$variable;

And stick to that in HTML: <table something="something"> use " " quotes thats why when you use echo '<a href="url.html"></a>'; you don't need no \\ or \" and etc. :rolleyes: and it is faster too.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.