I defined a constant:
define('ROOT_URL', dirname(__FILE__));
I am using it with a second part of a path to call on a png image.
<img src="<?php echo ROOT_URL ?>/images/folder1/logo-black.png" nosend="1" border="none" width="129" height="34" />
Image returns broken and my path is not as it should be. (But still when I link it, it shows me a image).
It's like:
C:\wamp64\www\email-signatures/images/folder1/logo-black.png"
It's with \ and / .
What am I doing wrong?
If you pass the browser an address like this C:\wamp64\www\email-signatures/images/folder1/logo-black.png it will look on the other guys PC for that folder and file. Remember you are passing text (HTML) to a browser on someone elses PC, for the browser to interpret and paint on that other PC's Screen. You need to pass a URL so the browser knows to go to your WebServer for the image.
You could use the whole http://domain........ but if you just use the relative folder name, even if you move this code to another domain, it should still work just fine.
So assuming the images folder is just below your DocumentRoot try
<img src="images/folder1/logo-black.png" nosend="1" border="none" width="129" height="34" />
Related
<img src="D:/xampp/htdocs/image_app/images/cardekho-pdf-logo.png" width="400" height="400">
I am using following code but the image is not displaying. Please tell me what wrong with source code
Buddy.? If u are using XAMPP why don't you try like
http://localhost/images/cardekho-pdf-logo.png instead of
D:/xampp/htdocs/image_app/images/cardekho-pdf-logo.png
Try like
<img src="http://localhost/images/cardekho-pdf-logo.png" width="400" height="400" alt="pdf-logo">
This is a windows link. Try hosting your image online, or use file://D:/xampp/htdocs/image_app/images/cardekho-pdf-logo.png but it'll be only available for you
try this one:
<img src="../xampp/htdocs/image_app/images/cardekho-pdf-logo.png" width="400" height="400" alt="pdf-logo">
You are using an image link on your local computer, if people will view your website.. the browser will try to locate the image on your visitors local computer.
Example. Juan create an image link pointing to his D: drive and uploaded the html to the internet. Juan can see the image since it is on his D: drive but Pedro can't see it. Pedro may even have no D: drive and if he have, the file cardekho-pdf-logo.png wont be even there.
To fix your issue since you are running XAMP. Load it from root folder or from HTDOCS
<img src="/image_app/images/cardekho-pdf-logo.png" width="400" height="400">
These are likely cause of the image not displaying
Ensure that the image is in the folder (in your own case images)
if the image exist in the folder, Ensure that the extension of the image is the same as what you specified, in you own case its png.
Also the folder is in your project folder
<img src="D:/xampp/htdocs/image_app/images/cardekho-pdf-logo.png" width="400" height="400" />
Do you have a closing tag? I added a slash so the tag is self-closing (so you don't need a seperate closing tag).
If possible, move the image to a folder inside the project like this
/root_project_folder/images
Doing this will allow you to use a relative path instead of a absolute path.
I am using PHP to upload images in my web application. The images are stored in some directory on the server while their paths are stored directly in MySQL database.
The upload goes very well and images get in the folder but the problem is accessing thoses images with their path field stored in the database : i am not yet able to find the correct form of the path i should use, now am using the realPath and dirname functions to help me get the path so finally an example of path is C:\wamp\www\webroot\img.png (since am on Windows using wampserver) So when i do something like :
<img src="$image->path" />
i get no image shown in the browser and when i inspect it i get the expected code like :
<img src="C:\wamp\www\webroot\img.png" />
which means that this path format is not correct to show the image.
I have tried many things : i took the same path and acced it with the browser and it showed me the image (with the file protocol automatically) so i added file:// to the image path but nothing was new. I have also tried to acces it as a web url and with that it goes will for example it shows the image when putting
localhost/webroot/img.png
But what i need exactly is being able to store and retrive the image file again. So is it a file system probelm ? is the code platform independant ?
I will be very grateful for any help
Thank you.
You can't show an image with its path, but with its URL.
In PHP, we use to save the filename only in MySQL and after, you display the image with <img src="path/to/img/<?php echo $image->filename; ?>" />
That's all!
Add the file protocal to your path.
<img src="file:///<?php echo $image->path; ?>" />.
The best thing you could have to done is save the image in a folder inside your project/website folder. Then save the path to the image from the root folder in the DB.
Example: I uploaded a an image of filename "image.png" inside "Img" folder in the Website Root Folder. Then I will save "Img/image.png" inside my DB.
So anytime I want to reference the image, I will just use
<img src="/<?php echo $image->path; ?>" />
Or
<img src="<?php echo $image->path; ?>" />
Sorry for wasting your time, i have solved the problem. It was an issue with how my application is accessed. It should be accessed from only a directory called web so every path should be referenced from that directory !!.
<img src="d:/Tulips.jpg" >
</img>
<img src="file:///d:Tulips.jpg">
How to retrieve and show images from another drive using src attribute in <img> tag?
If the image is in the same folder it works but when the source of the image is on another drive it's not working.
jpgYou can't put your file system path in the src unless you open it from your desktop or your computer. You can try to pass the file as base64 encoded strings. I'm showing how to do it in PHP because you tagged this question with PHP
$image = file_get_contents('d:/Tulips.jpg');
$image_codes = base64_encode($image);
And in your html put it like this.
<image src="data:image/jpg;charset=utf-8;base64,<?php echo $image_codes; ?>" />
Try
<img src="file:///d:/Tulips.jpg">
You were missing a slash after your drive lettter.
The reason is you are doing the inevitable.
HTML markups cannot read data from the local disk drives, you need to put them in a folder or access it from the same directory for this to work.
Since, when you publish your website images are to be accessed from the folders of your webserver, accessing from a hard-drive directly (not possible via HTML though) puts you under potential risks.
On my html page, I make use of images which are housed in a local folder. The paths are coming directly from the database field. How can I do this? I know it wont work if the images are not in the web root directory. Can symlinks work?
For example,
The physical path to the images is c:/Images and the database field will contain the path like this, photo/image1.jpg
I will fetch the image source path from php as shown below,
<img id="image1" src="<?php echo $this->object->imagePath; ?>" class="img-polaroid">
$this->object->imagePath here will be the string concatenation of c:/Images and photo/image1.jpg. So, putting it together t will be c:/Images/photo/image1.jpg
The problem is it does not show up. I have tried this as well to test,
<img id="image1" src="file:///C:/Images/photo/image1.jpg" class="img-polaroid">
But no luck.
first let me know if putting just C:/Images/photo/image1.jpg in a browser address bar brings an image or not. If not then that's mean you are giving wrong path. Let me know so i can edit this answer. But for now this is the answer i hope.
Symlink to the folder worked like a charm.
I used symfony 1.4 to make a basic form that contains an image upload widget, (which uploads the image just fine) but when I try to echo the image later on it doesn't show.
This is the code I use to (try to) output my image:
<img src="<?php echo sfConfig::get('sf_upload_dir').'\\'.$post->getImagename() ?>" />
A quick peek at firebug shows me that firefox "failed to load given url". but if I copy & paste the url into the address bar it loads the image just fine.
(Please note, I am developing on a windows environment and my project directory contains no spaces.)
Can anyone explain to me why this happens or what I am doing wrong?
You shouldn't use the sf_upload_dir key because it returns the full path to the image inside the webserver. Like: c:\website\project\web\uploads.
You should use sf_upload_dir_name instead, which returns the path to the uploads folder inside the web folder.
Try:
<img src="/<?php echo sfConfig::get('sf_upload_dir_name').'/'.$post->getImagename() ?>" />