Hi I'm new in PHP and for now, I'm working on a website for myself (using: HTML, CSS, bootstrap, PHP)
but when I'm testing the website in the tools.pingdom.com
this is the image of the warning says:
"Serve the following static resources from a domain that doesn't set cookies"
and because of this gave me a bad grade, you can see the code in the button, it's a very simple code
<img src="source/<?php echo img; ?>" alt="1.jpg" class="img-thumbnail">
what should I do to solve this problem, and how should I serve dynamic data
THANK YOU
obeidarash.ir
Could you please try that code :
<img src="source/<?php echo $img; ?>" alt="1.jpg" class="img-thumbnail">
And one more important thinks that message is suggesting that if your website is www.test.com, then you should load static content from www.companycdn.com. And that new site (www.testcdn.com) is a simple static website that does not serve cookies.
To do this, you need to upload your static resource (e.g. images) to the second domain.
And then update the paths of images to the new domain. For example, instead of this: <img src="logo.jpg"/>, you should change it to this <img src="http://www.companycdn.com/logo.jpg"/>
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 !!.
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']); ?>" />
In my wordpress site, let's say I have an image that is located in:
/wp-content/themes/root-theme/assets/img/image-1.png
If I want to access this image in a blog post, when using the html editor in Wordpress I have to type out:
<img src="/wp-content/themes/root-theme/assets/img/image-1.png" />
This generates a url of:
http://my-site.com/wp-content/themes/root-theme/assets/img/image-1.png"
This is a massive pain. I'd much rather be able to write:
<img src="/img/image-1.png" />
That is, I want to make it possible to access my assets folder from the root directory, so that the image above could be accessed via:
http://my-site.com/img/image-1.png
Is this possible to do or would it majorly screw up the rest of the site?
You'll have to use the media manager, it will write the full link out for you, no need to type anything. Just above the editor click "Add media", select your image, click insert into post and you're done.
Use bloginfo function to get full url of your theme :
<img src="<?php bloginfo('template_directory');?>/assets/img/image-1.png" />
Output: http://my-site.com/wp-content/themes/root-theme/assets/img/image-1.png
Reference
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() ?>" />