473,769 Members | 5,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

images not showing with require_once

41 New Member
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
Expand|Select|Wrap|Line Numbers
  1. <?php require_once("included_files/hdr.php");?>
  2.  
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
Expand|Select|Wrap|Line Numbers
  1. <?php require_once("../included_files/hdr.php");?>
  2.  
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
Expand|Select|Wrap|Line Numbers
  1. <?php require_once("../included_files/hdr.php");?>
  2.  
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.
Expand|Select|Wrap|Line Numbers
  1. <img src="images/home_icon.gif" alt="" width="13" height="12" style="padding-bottom:5px" />
  2.  
thanks
vineet
Dec 1 '08 #1
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
Dec 1 '08 #2
vinpkl
41 New Member
hi dlite

making my images path change to
Expand|Select|Wrap|Line Numbers
  1. <img src="http://localhost/test/images/samsung_logo.gif" width="111" height="50" />
  2.  
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
Expand|Select|Wrap|Line Numbers
  1. <img src="http://localhost/test/images/samsung_logo.gif" width="111" height="50" />
  2.  
then again for live server view i have to change the all images path in all pages to
Expand|Select|Wrap|Line Numbers
  1. <img src="http://domain.name/images/samsung_logo.gif" width="111" height="50" />
  2.  
is there anything we can put in some variable for images and images can take path from there.

vineet
Dec 1 '08 #3
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)

Expand|Select|Wrap|Line Numbers
  1.  
  2. define("BASE_URL","http://domain.com/"); 
  3.  
  4.  
in the images you would do

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php echo "<img src='" . BASE_URL . "' alt='My Image' />"; ?>
  3.  
  4.  




@vinpkl


Dan
Dec 1 '08 #4
vinpkl
41 New Member
hi dlite

thanks very much. your code worked great.

now everything is working fine and showing up as i wanted.

vineet
Dec 1 '08 #5
dlite922
1,584 Recognized Expert Top Contributor
Glad I helped!

See you around,




Dan
Dec 1 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
38340
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')?>
4
7337
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...
11
41094
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)...
6
1973
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...
2
2053
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);
0
1292
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...
10
13414
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...
6
2075
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
14
3005
anfetienne
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...
0
9423
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,...
0
10216
Oralloy
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...
1
9997
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,...
0
9865
tracyyun
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...
0
6675
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();...
0
5309
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...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
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
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.