I have a few websites that are in a single folder for example:
en
de
nl
fr...
in these folders are the websites.
What I want to do is add an images folder into here and have all of the sites referencing this images file. The reason for this is so when I add another image I only have to do it once not multiple times.
My problem is that I can't seem to find a way to reference to this file. I'm not sure if its possible becasue it is before the site roots.
Is there any way to do this?
You can either do it as a virtual directory which you include in all your sites, but a stronger approach would be just to make it a site by iteself. Chances are if you are using it for images, then its purpose is to serve static content.
What i would do is create a site named static.yoursite.com and in that site have a few folders (css img js). Then when you need to load an image from any of your sites you would do it like this:
img src="//static.yoursite.com/img/global/background.png" or
img src="//static.yoursite.com/img/de/welkome.gif" or
Having it all in a separate site might make it easier to migrate to something like S3 or a real CDN like cloudfront in the future. It will also make it super easy to set the proper expires headers and caching for static content.
Related
When we setup laravel, the default url will have "public" on it.
Example : localhost/laravel/public/users
We know that we always wanted to remove the "public" in our url specially when we go to production.
I searched in the internet and looks like removing the "public" url needs some work to achieve like moving files to other folder, modifying .htaccess, etc...
My question is, whats the purpose of "public" url?
Why doesnt laravel provide an easy way of removing the "public" url..
I know Laravel is popular these days but why give beginners a headache in just removing a part of the url?
Let me know your thoughts
The public directory holds all your files that should be accessible from the outside.
This way nobody can access any other file in your application.
How do you remove the public in your URL? Well you don't "remove" it at all. Instead you should point your domain (virtual host) directly at public (this is called Document Root)
If you don't have the possibility to do that (usually because your on a shared hosting with very restricted permissions) then and only then you need to move files or use a workaround with .htaccess. However if your hoster doesn't allow you to set the document root I would consider to switch to another one...
By the way: This is not really unique to Laravel. A lot of PHP frameworks do it (Zend Framework, Symfony, etc) all have a dedicated directory for files that should be accessible - separated from the framework core and your application.
If you're having trouble setting up your development environment correctly, you should try out Laravel Homestead. It's a pre-configured Vagrant box that makes it very easy to get your site locally up and running (also comes without public in your URL!)
When you make your site's root point to the public folder, e.g. www.mysite.com points to /path/to/laravel/public, there are a few advantages.
Your files outside of public, like your .env with your passwords cannot be accessed doing things like www.mysite.com/../.env and other common "exploits" are prevented just by taking this simple approach.
It's quite a common pratice in other frameworks too, not only Laravel or PHP.
I'm writing a website that assigns URLs under the root domain to various user-specified records, so I'm trying to leave as many top-level paths unused as possible. Thus, I'd like to put everything in public, including assets, under a subfolder (e.g. 404.html would become edit/404.html, assets/users.css would become edit/assets/users.css, etc.). Is there a simple and sane way to do this that'll keep things like image_tag working?
I've been trying to reduce the amount of copying and pasting of content files across some of my projects and decided to go down the adding files as links from a central project.
The problem I have now is that the System.Web.Optimization.Bundle.AddFile(string virtualPath, bool throwIfNotExist = true) does not work as the file doesn't really exist in the directory I specified.
Does anyone have any pointers? Or maybe an alternative to linking content files?
Thanks.
I think you cannot access files outside of your web project with the virtual path system and It might hurt when you want to deploy your app.
I suggest to make a custom project for your static content with a custom domain: e.g. static.yourcompany.com and reference all this files from this domain. This also has the advantage that the browser does not have to add the cookies for authentication and tracking to these requests, which might be faster if you have a lot of traffic. You can also open your custom cdn (http://www.maxcdn.com/pricing/) or store the files in azure or amazon aws (which is more or less free for less files and traffic).
Another approach is to make some batch files to keep your content files synced.
I have the following folder structure in my zend framework 2 tutorial project in Ubuntu:
/zf2tutorial
/module
/Album
/view
/album
/album
myImage.png
index.phtml
in my index.phtml code I have a line such as this:
<img alt='SMALLIMG' src='myImage.png'/>
this does not work.
If I change the myImage.png to be http://www.someurlhere.com this works fine.
How do I load in myImage.png instead? I tried giving it the direct URL:
/home/myUsername/NetBeansProjects/zf2tutorial/module/Album/view/album/album/myImage.png
I've also tried doing the following:
../myImage.png
but neither of these worked.
Also please note, it has to be a bad path (I must be doing something wrong here) because the broken image icon shows up... indicating there is a linking problem here.. the direct URL is copy pasted from the properties section of the image itself..
It's not a problem of image or path. You are trying to make an impossible thing.
You certainly define in your virtualhost configuration that the documentRoot is your public directory.
That means your web server will give access to resources located from this public directory.
You have to put your resources from this public path (css, images..) or you can define a symbolic link if you allow followingSymlinks.
Hope this helps.
<img alt="" src="img/2 header960.png" align="center" >
The fundamental issue you are confusing is the difference between views vs public content.
View files are essentially HTML templates into which you can inject certain values at runtime. Your directory structure correctly places this stuff within a views directory inside your module. These template files themselves are never exposed to the end-user. They are only used by the application to generate fully-populated HTML chunks that are eventually sent to the browser.
In contrast, static assets - like images, javascripts, external stylesheets, etc - are served directly by the webserver to your visitors. As such they need to be in a directory that the webserver has been told to publicly serve to visitors.
The easy thing to do is to simply move directories containing these static assets out of the module and into the app's public folder.
But this is undesirable in the sense that you might reasonably want the module to be a self-contained entity: it can contain its own routes, its own controllers/actions, and, in particular, its own static assets.
So, how to make the webserver reach down into the module and treat some of the content there as "public"?
The answer is to use an "asset manager", a component that links certain module content into the app's public directory. Typically this means:
Activate the asset manager module
Create a public directory inside your module
Place those static assets there
Inform the asset manager which public module directories into the public app directory.
Take a look at the AssetManager module by Roberto Wesley Overdijk and additional instructions for use.
[As a side note, welcome to the world of web development. ZF2 is a great framework, but it's not the easiest thing for a beginner. It provides a lot of flexibility for doing things in a "good way", but it can certainly come off as convoluted at first. Try not to get discouraged. ;-)]
the reason may be the image extension (.png)
please check your exact extension case, is it written in small or capital case???
update your image link exactly as like the name of image.
eg.
myImage.png or myImage.PNG
try to look for an .htaccess file somewhere in your dir most probably on module folder..that file blocks the access for the image you are trying to link..(my basis here is my application in yii which fails to show the image even if the path is correct)
you may create an images folder in your home dir: /zf2tutorial/images for example and put all the images there calling it: src="/images/myImage.png"..
or
find the htaccess im talking about, change the restrictions(or delete it:|) and you can use this path: src="/module/Album/view/album/album/myImage.png"..
<div id='small_image'>
<a href='/feeds/posts/default' title='smallimg'>
<img alt='SMALLIMG' src='c:/home/myUsername/NetBeansProjects/zf2tutorial/module/Album/view/album/album/myImage.png'/>
</a>
</div>
I cleaned up someone's style sheet for a Dreamweaver site, by editing the css directly, and now the secretary is having trouble using her old template.
Most of the files in her site reside in subdirectories of the 'upload' directory. For example, I would have expected to see the stylesheet in
../assets/css/ etc.
but in fact I'm finding it in
../upload/assets/css/ etc.
In addition to assets, I am also finding Templates and images as subdirectories of 'upload'.
Do you know why this 'upload' directory was used?
I am considering two possible approaches.
(1) Make sure everything needed is in ../upload/ and remove the subdirectories that are directly in the root directory
(2) Edit the template to remove all references to ../upload/
Note that (2) appeals to me because the file structure will be simpler; but I wonder if the client has some sort of extension in her Dreamweaver that causes everything she ftp's to be put into the 'upload' directory.
Note that so far I have copied my cleaned up css file over to ../upload/assets/ as a short-term solution. But they want to be able to make changes to their template, and add new pages, on their own in future.
Thanks.
The likely problem is how she has her FTP remote settings specified. It appears that it now points to the upload folder rather than the web root. Or, it could be that her FTP user account is tied to the upload folder rather than the web root.