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" />
Related
I am trying to use the get_option() function in Wordpress to set the SRC of an image in a theme file. The file is index.php, and represents the homepage.
The current image code is:
<img class="outside-collage-image" <?php echo 'src="'.get_option('article-image-1').'"'; ?>>
However, the image doesn't display, and when I inspect it, it simply says src(unknown) where it should have the proper SRC
I have tried a myriad of fixes, including leaving the SRC out of the php area and simply calling the function, but it doesn't seem to work.
The oddest part is, if I put on the page <p><?php echo 'src="'.get_option('article-image-1').'"'; ?></p> to check the output, it outputs into the <p> the proper code: src="http://image-site.com/my-image.jpg" (obviously the link to the image is fake, but the point is, it's a valid link.)
Any idea what could be causing this?
You can try this to get the image article-image-1.jpg in your root.
<img class="outside-collage-image" src="<?php echo get_site_url().'/article-image-1.jpg'; ?>">
It turns out that I screwed up, and the above function works just fine. I was simply applying it to the wrong image, and didn't realize that until looking at it a day later, when it wasn't 1:30 AM and I wasn't so tired. Thanks to all that answered.
headdesk
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 !!.
how can i set image url in page ?
In image you can see I have tried by three ways but it not work.
Images are located under image folder of active theme.
You have three image tags all pointing to different urls of which two appear malformed.
The middle image tag in your screenshot seems the most accurate but you may want to add a semicolon after the right paranthesis.
If all three files are supposed to refer to the same image, then replace the first and last image tags with the middle one.
Then if it still doesnt work then replace bloginfo('template_directory') with the actual location to the images relative to document root on the server but put the value in quotes. For example, if your images are in the subfolder images in folder imageset on your site, then you could use
"http://www.whatever.com/imageset/images" or "/imageset/images".
which results in the code:
<img src="<?php echo "/imageset/images"; ?>/images/banner1.jpg" alt="">
or even better:
<img src="/imageset/images/images/banner1.jpg" alt="">
Try as follows <img src="../images/banner1.jpg" alt="">
I have a main domain that users can upload images to which are then viewed in a slider so multiple images (sometimes up to 50) are loaded by the page on loading. I am trying to access the same images on a subdomain but it isn't working very well.
If I use
<img src="<? echo 'http://www.mysite.co.uk/'.$row['imageLocation']; ?>">
the images load but it is very slow
If I use
<img src="<? echo '/home/myname/public_html/mysite.co.uk/'.$row['imageLocation']; ?>">
the images aren't displayed despite the path being correct. If I use the same path for getting the images sizes (getimagesize) it returns the correct results so I'm sure the path is correct.
The images arent shown because you echo the path to the user first, but not the file itself and then the users browser loads them asynchronously. He cannot access any parent directory from mysite.co.uk only child directories.
The PHP can load them because it runs on the server itself before it is returning anything.
What you could do is using the readfile() function from PHP in an extra PHP file like getimages.php or just use the first solution, which cannot be improved in speed except you will change the image sizes, which might be your main problem here.
If you want to directly echo image file content, use this.
<img src="data:image/jpeg;base64,<?php echo base64_encode('/home/myname/public_html/mysite.co.uk/'.$row['imageLocation']); ?>" />
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.