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.
Related
I need to insert php code within a text. It is an image but uses an absolute path through php. I would like to execute but the image is not displayed within the text.
<img class="image-left" src="<?php $_SERVER['DOCUMENT_ROOT']?>/abuelo/abuelo.png"/>Since the founding of Grandpa in 2003 we have offered a different type of shopping. We have always had service...
I always use in my projects Because I find very useful, if you change the place .php file or meta in a folder always find the images.
I would be very utilizad it can also be included in the database, in case I need to show information with your image added elsewhere on the page regardless of where the file is hosted.
Is there any way to insert the image in the database and make it work?
All you need is an echo
<img class="image-left" src="<?php echo $_SERVER['DOCUMENT_ROOT']; ?>/abuelo/abuelo.png"/>Since the founding of Grandpa in 2003 we have offered a different type of shopping. We have always had service...
Edited:
The problem is, you are referencing your image as,
C:/wamp/www/
which will never work. You should be referencing it as localhost. Like this:
<img src="<?php echo "http://" . $_SERVER['SERVER_NAME']; ?>/abuelo/abuelo.png" />
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.
I'm completely new to PHP and I'm writing a page which displays some images from my hard drive.
I've tried different syntaxes and none of them worked out for me ...
I've tested
echo '<img src="/var/www/netbeans/PhpProject2/Plate.jpg" alt ="Test" />';
and It didn't show anything for me .... I've tested this code Also and it didn't worked for me too, I've attached My monitor screen page below. as you can see it seems that my images are not found. I've pasted every address of my images in my browser separately and I was able to see them but when I add them in src argument of img function I'm not able to see them!
What do you think might be the source of problem .... I need to work on a project which needs to be fast enough in working with images.. what do you think I should use ? is "
Try to remove the /var/www. Path should be the http path not the file physical path.
echo '<img src="/netbeans/PhpProject2/Plate.jpg" alt ="Test" />';
I've been looking all over the place but can't seem to find an issue quite like mine. Maybe I haven't been putting together the right keywords; but perhaps I'll have more luck just explaining my issue.
I've put together the following little code:
$image_types = array('gif','png','jpg');
$recent = array();
foreach($image_types as $image_type) {
foreach(glob('first/second/*.'.$image_type) as $filename){
$recent[$filename] = time() - filemtime($filename);
}
}
$recent = array_keys($recent, min($recent));
$recent_img = $recent[0];
What it's supposed to do is look into a specific folder and find the latest image and, later, place it into the webpage. What it does do is find the latest image, path and all. So everything is working up to there. If I echo $recent_img I get the latest image's src, so obviously I'd want to place the following code right after: <img src="<?php echo $recent_img ?>" /> and I should get the image. Surely enough, everything works fine, even up to the point locating within the HTML an <img> that refers to the image I need. HOWEVER, there's something going haywire at this point!
If glob() is set to the path first alone, the code works entirely: the image is shown in the website. But with the second folder added, it does everything except show the image on the website.
So I go to the result website and check the source code and the image code is as follows:
<img src="first/second/img.jpg" style="display: none !important; visibility: hidden !important; opacity: 0 !important; background-position: 0px 0px;" width="0" height="0">
Notice the display:none!important the visibility:hidden!important etc., almost like the CSS is set to do everything it can to avoid showing the image. Including setting the width and height to 0 when the image is obviously not 0 x 0 pixs. (Just in case: nor is there any instance in my style sheet which would result in setting everything to 0 and hidden and etc. on any image in my project.)
However, as I said, this does not happen when the path only has the one part, the folder first. I've tried putting all the images from one folder into the other and still the issue remains. I've edited the CSS values on the spot in Chrome and still nothing.
It seems like an absurd issue to have because nothing is changing except the code is looking for a file inside of a folder that is inside a parent folder. Moreover because the code actually works to the point of showing the file I need and its path but not the file itself.
Online trial example for you guys to see and TEMP solution or, rather, 'workaround'.
I hate working around an issue. It usually complicates things and/or makes them messy. First of all, in this case it is an organization issue. It's much better to have ALL images in one folder and then make sub-folders for different kinds. Having many image folders floating about the root is not a good idea to me. Second, it seems absurd to have to use a 'workaround' when there seems no logic in the error. Third, I really would like to learn what is going on and not turn this into a PHP Bermuda Triangle. So please don't take my TEMP solution as me giving up, and please continue the synergy of this wonderful place, where no doubt at some point we'll arrive to a solution.
At any rate, the 'workaround' you've probably already guessed is to place the second folder in the same directory as the first folder, which is the root. So this should solve that specific issue. But it's not a genial solution if you ask me.
I've been asked to upload an online trial of the issue and I've done so >>HERE<<. You'll be able to see the same code looking for the latest image in first/second/ and in first/, and you'll see that one works marvelously where the other mysteriously flops!
QUESTION: Just occurred to me. Could it have something to do with the length of the path name? I.e. first/ is O.K. but first/second/ is too long? Doesn't make much sense taking into consideration that the retrieval of info from the path is successful, and the issue is rather on the side of the HTML outcome, but I have since tried placing the second folder in the root and gave it a 10-letter name and the issue was recreated. This, however, only happened in WAMP localhost, as when I uploaded everything online, the length didn't seem to matter. However, even online, as you can see from my LINK the first issue remains.
You can try retrieve the src and update using jquery:
$.get('image.php').success(function(src) {
$('#myimg').attr('src',src);
});