hi all
i m having problem with including files and images geting disappear.
i have images folder on the root.
i have hdr.php in my included_files folder on root.
if i include hder.php in my files that are on the root with this code -
<?php require_once("included_files/hdr.php");?>
-
then all the images of the header.php are shown perfectly alright.
But
if i include header.php in my files that are inside any folder on the root with this code -
<?php require_once("../included_files/hdr.php");?>
-
then all the images of the header.php are not shown. they disappear.
Like i have folder2 on root. and there is file2 inside folder2. Then i used this code -
<?php require_once("../included_files/hdr.php");?>
-
to include my header file. but with this code my images of header.php file disappear.
i m not able to understand as we use "../" if the file is inside in any folder on root.
when i view the html source in explorer then i get the same path on both pages whether the page is inside any folder or on root. -
<img src="images/home_icon.gif" alt="" width="13" height="12" style="padding-bottom:5px" />
-
thanks
vineet
5 2838 dlite922 1,584
Recognized Expert Top Contributor
image paths do not change with the path of the PHP file you're in.
If you include a header in a php file that's inside a folder then your images in header need to be changed and have ../ added to them.
Header.php file get's pulled into your subdirectories file as if you the code was exactly put there. And of course the img folder is not relative to this subdirectory and therefore it will now show.
If you have the following
index.php
img/
img/foo.jpg
include/
include/header.php
folder1/
folder1/test.php
and you include header.php in test.php the images in header must be relative to test.php (such as src="../img/foo.jpg" )
if you include header in index.php, your images must be relative to index.php.
(such as src="img/foo.jpg" )
HOW TO SOLVE THE PROBLEM:
either correct your relative paths. (copy images to subdirectories) or use the FULL address for the image (ie http://yourdomain.com/img/foo.jpg )
Good luck,
Dan @vinpkl
hi dlite
making my images path change to -
<img src="http://localhost/test/images/samsung_logo.gif" width="111" height="50" />
-
works fine and show images on all pages whether page is in any folder or outside on the root.
but with this change first for localtesting i have change all images path to -
<img src="http://localhost/test/images/samsung_logo.gif" width="111" height="50" />
-
then again for live server view i have to change the all images path in all pages to -
<img src="http://domain.name/images/samsung_logo.gif" width="111" height="50" />
-
is there anything we can put in some variable for images and images can take path from there.
vineet
dlite922 1,584
Recognized Expert Top Contributor
yes, define a constant in a config file somewhere that should contain your site-wide variables (Database login, etc) -
-
define("BASE_URL","http://domain.com/");
-
-
in the images you would do -
-
<?php echo "<img src='" . BASE_URL . "' alt='My Image' />"; ?>
-
-
@vinpkl
Dan
hi dlite
thanks very much. your code worked great.
now everything is working fine and showing up as i wanted.
vineet
dlite922 1,584
Recognized Expert Top Contributor
Glad I helped!
See you around,
Dan
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: the wonderer |
last post by:
This is an elementary question, but I've not been able to find the
answer, so here goes:
I am developing a site using php. I have the html header information
in a file that I include in all the pages using the require_once
function.
That is, each page includes the line
<?require_once('PageStart.php')?>
|
by: Gregory |
last post by:
Hello,
I've managed to build two web pages, one that can display images with
associated text data in a table, and one that can resize and display images
without the text. I'd like to resize the images as I go, without writing
them to disk on the server. Do I need to prepare all of the resized images
before I display the data from the select (which is put into an array by
php). How can I display a resized image in a table, without writing...
|
by: Kimmo Laine |
last post by:
I'm flipping my wig here, people. I'm using classes and making each class a
file. when I'm including dependet classess, I use require_once to avoid
multiple declarations - yet they happen. I put debug_print_backtrace in the
file to see how it is included, and here's the output:
#0 require_once() called at
#1 require_once(\eKirje.textGrid.class.php) called at
#0 require_once() called at
#1 require_once(\eKirje.kanava.class.php)...
|
by: The Numerator |
last post by:
I have a folder full with images, and for security reasons I don't want
anyone to know where the folder is. So, to call images, I know there is
a way to call like a PHP file instead. For example Galley 2 (a
PHP-enabled photo album) safetly tucks away the actual images and in
the image source, it calls for something like
"main.php?g2_view=core.DownloadItem&g2_itemId=12&g2_serialNumber=3".
How do you do that? Do you need to use the...
|
by: K. A. |
last post by:
I'm trying to write a web site for storing staff ID's together with
their photos using a PHP form. A user of the site should be able to
enter his ID, name, and select a file from a directory as his personal
photo.
Step 1. Created the table in SQL.
SQL> create table file_test (
StaffID number(5) NOT NULL,
StaffName VARCHAR2(30),
Staff_pic bFile);
| |
by: Svein Erik |
last post by:
I'm developing an application in C#.NET 2005.
The app is going to have an image with a specific size, let's say 800x600
px, this is a map of a go-cart lane. And on top of this image i'm going to
place small images with traffic lights.
I have the code for changing the images according to which light should show
in the traffic-lights, what I don't know is what the best way to place the
main image (map) and the traffic light images on top...
|
by: eholz1 |
last post by:
Hello Members,
I am setting up a photo website. I have decided to use PHP and MySQL.
I can load jpeg files into the table (medium blob, or even longtext)
and get the image(s) to display without a problem. I am using
chunk_split(data) and the base64_encode and base64_decode on the files.
I do a select from the database, and then echo the image (with
header(Content Type: image/jpeg)
and the decoded image displays fine. Yes, I have...
|
by: Shelly |
last post by:
Here is a crazy question that has happend to me once before.
I have an include file for the connection information to the server. It is
like this:
$hostname= "the_server_location";
$database = "the_database_name";
$dbUsername = "the_username";
$dbPassword = "the_password";
$dbCon = mysql_pconnect($hostname, $dbUsername, $dbPassword) or
|
by: anfetienne |
last post by:
Hi,
i went through a tutorial on how to display images stored with a directory and it came out good but i have a problem.....when i upload less than 5 files it displays the 1 image and then shows broken image placeholders. If i don't upload in sums of 5 then these broken image places holders keep showing, and instead of the images displaying row by row it goes by columns.
Below is the code to display....can someone tell me where i've gone...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |