Jump to content

i cant load an image from another dir


alwaysbrasilian

Recommended Posts

This is such a basic thing that i feel a little embaressed but i need the help. I want to load an image from another site. also if i make a link inside the file.php('index.php') i can use it only while inside the index.php but if i want to use it in folder 2 it displays 'Not found.' I've tried '../' but then it only works inside folder2 and not index. You can see i tried using chdir, opendir, readdir and no luck. what function/command can i use for this?

file.php

<?php
echo "Hello world!". "<br>";
echo getcwd();
?>
<img  src="house1.jpg" />
<a  href="index.php"> back to index </a>

 

index.php

<link  rel="styleSheet" type="text/css" href="template.css" />
<body>
<p>index</p>
<a  href="folder/folder/folder1/folder1.php">
folder 1
</a>
<a  href="folder2/folder2.php">
folder 2
</a>
</body>

 

folder2.php

<?php
chdir('/wamp/www/test'). "<br>";
print getcwd();
print opendir('/wamp/www/test');
include('file.php');
?>
<link  rel="styleSheet" type="text/css" href="../template.css" />
<body>
<p>folder2</p>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/153489-i-cant-load-an-image-from-another-dir/
Share on other sites

not exactly. i have a file which lets call top.php inside folder main with other .php and html files. Now if I use the include function of php in my other .html/php files in different folders links and pictures wont display because file thinks its inside the main folder but in reality its two or three directories back and all links and pictures don't work unless i use '../' but inside the original folder with all other files it then wont work. So any ideas on how to link all files to top.php and still be able to use the links and pictures..

IT WORKS!!, i only understood relative path and didn't completely understand absolute path until now.. so simple i would kick myself if i could. All this time ive been trying '/wamp/www/main/top.php' and i never thought that if i used 'http://localhost/test/top.php' would work. thanks again

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.