By davecoventry on
I'm getting broken links to my images.
The image files are at http://www.example.com/sites/default/pictures/users/
file_exists(sites/default/picture/users/mypic.jpg); returns 'TRUE'.
but print '<img src="sites/default/picture/users/mypic.jpg" />'; shows a broken link.
Furthermore, the broken link appears to point to 'http://www.example.com/node/79/sites/default/picture/users/mypic.jpg'
What is going on?
Is there any way to make sure that my links do not have these additional sections inserted?
Comments
There are to ways to link to
There are to ways to link to files, relative and absolute. sites/default/picture/users/mypic.jpg says: look for a sites directtory as a child of the current folder I'm in. That is a relative path. So, if you're here:http://www.example.com/node/79/ and you have the above as the path to the image, your browser thinks you're in the /node/79 folder and thus adds the image path to that path resulting in: http://www.example.com/node/79/sites/default/picture/users/mypic.jpg
So, you should start you image urls and other links with the base path of your site. If your site is in a folder like: example.com/mydrupalsite then your base path is /mydrupalsite/ if your site is simply at example.com, your base path is / . SO, change you image link to be '
; assuming you arnt running drupal from a sub folder. This is an absolute path
Also, it seems from the link you posted that your drupal node urls have a / at the end, like: node/79/ - There should be no trailing slash.
You can use the $base_path
You can use the $base_path global variable or the function base_path() to get the base path of your site.