I have a laravel project that i hosted on a shared host. using the system i saw on Laravel Deploy Instruction
So am suppose to upload image, -- user's image. To the public_html folder but since am not in the public_html so the users can't upload their image. since my code lie out side the public_html folder and it doesn't allow write permission for general users. so i tried uploading it to 'storage folder' (ie the my laravel project folder, that is in the sane level as the www 'public_html' folder.) it works i can see the image in the storage folder but i cant access because it is behind the public_html folder. and whatever can't be point to. Example project/storage/app/public is the folder that has the user image if i point to it in <img src="project/storage/app/public/user.png" > it wont display because the browser looks for project/storage/app/public inside the public_html folder whereas it is outside the public_html. So can someone touch on this. Thanks guys. Or is htaccess use in this case?
you need to create symlink to Your storage folder .
please see this answer:
Laravel 5 - How to access image uploaded in storage within View?
the above method given by the link works for offline however not all shared hosting site support artisan Laravel sysmlink. so the absolute and best way to do this is with php symlink() function From PHP MANUAL
so just add this code to your web.php ie project\route\web.php
Route::get('/symlink', function()
{
if(symlink('/home/username/projectfolder/storage/app/public', '/home/username/public_html/storage')){
echo "We rock yea stackoverflow!!!! best programming software";}
});
so the username is the name of your home dir
Related
I zipped all my files before uploading it to elastic beanstalk. However I'm getting an error message:
Not Found
The requested URL /was not found on this server.
I did some research and came across the following post:
https://forums.aws.amazon.com/thread.jspa?threadID=127927
"The '403 Forbidden' error was because of the file structure of the zip folder. In order to upload properly please highlight/select all the contents "inside" the folder then you can compress/zip the contents and not the folder itself. That is, you cannot have a nested folder inside the zip."
I have done as told, except that I have selected the files AND 2 folders which contain some files. This may be causing the issue(?)
What should I do?
As you have mentioned that you are facing “The requested URL /was not found on this server”, you need to ensure the following:
1: Make sure your application has the file that .htaccess is
redirecting to your welcome page. 2: You need to set the public
folder as the root folder. For this, go to the Elastic Beanstalk
Console and Click on “Configurations”, then modify Software . Update
the “Document root” to the folder that contains your site's
default page. For example /public if the welcome page is in a folder
named public.
I installed two codeigniter for desktop and mobile version. My directory structure is as follows:
www/projectfordesktop/application
www/projectfordesktop/uploads
www/projectfordesktop/projectformobile/application
My problem is that when I upload files from mobile site I want my file to be uploaded in main codeigniter application www/projectfordesktop/uploads. So, I want to access main codeigniter application base_url to www/projectfordesktop/projectformobile/. How is it possible.
I made two project because it redirect to m.project.com when accessed from mobile. And when access from desktop project.com. Is it good idea. If not, then is there any way I can use seperate view for mobile and desktop. Please help.
Thank you.
For security and a bunch of other reasons you absolutely do not want the upload folder in your application folder. And if at all possible you want your application folder and system folder above the public root. The other consideration - its possible and in some ways desirable to rename your application and system folder. So if your public folder is www
desktopapplication/www/
mobileappliction/www/
system306/www/
Now they are all safely above the public www, and they are labeled for what they are. Next you can have folders in the public folder, that contain the main index.php file for the specific application.
www/projectfordesktop/index.php
www/projectformobile/index.php
Open up the index.php file and redo the file paths to the application and system folder. Like
$system_path = '../../system306';
$application_folder = '../../desktopapplication';
The upload folder will now be either in www or one of the folders like projectfordesktop. Typically you would also put your css, js, etc files in there as well.
www/projectfordesktop/upload/
www/projectfordesktop/css/
www/projectfordesktop/js/
www/projectfordesktop/img/
Now - all the files which are public - are in a public folder. All the files which should be kept private - your application and system folder - are not public. And because you have labeled your application and system folder it makes it much easier to switch to different versions or revert back if needed.
I have a CakePHP project uploaded to the server:
httpdocs/cakephp/app/...
My domain name, for example www.mydomain.com is directed to httpdocs/cakephp
Now.. I need to access an image folder that it's otside the webroot of CakePhp:
httpdocs/resources/images/...
The problem is that I can't see files outside the cakephp folder when I go to www.mydomain.com, If I try with ../../resources/images.... I just get www.mydomain.com/resoures/images with an error.
How can I solve this?
Thank you!
Just symlink the resouces folder in your webroot folder.
Alternatively you can send the files through php. The CakePHP book describes this here for >2.3 and here.
Also it is not a good idea to put the whole cake folder in the root of your domain, you should set your app/webroot has the root of your host.
I'd like to put my images/assets in folders at the same level as my application directory, but every I try to link to an image, I get this error:
Forbidden
You don't have permission to access (my base url)images/myimage.jpg on this server
This how I'm trying to access the image in my view:
<img src="<?php echo base_url(); ?>images/myimage.jpg">
Is this an issue with my routes.php? I haven't really touched it, nor have I created a .htaccess file.
If the issue is that I haven't told it how to handle the base_url + some_asset_folder, where and how do I go about configuring that? I only know how to tell the routes to use a particular controller class and method, not to access a particular directory.
I'm new to PHP frameworks and a new to CodeIgniter – any help is much appreciated! Thanks so much.
The best way to keep your images, stylesheets, javascript, uploads etc. files are separate from the application. Create a folder assets in the root folder that contains application and systems.
So it'll contain the folders application, assets, system etc.
Add folders inside assets -- images, css, js, uploads etc.
and you can access it using
<img src='<?= base_url() ?>assets/images/image.jpg' />
This would probably be the best way to do it. This is what I've been doing for my applications, so for me this is the best way. Hope this helps.
Please check your .htaccess file that might be causing problems .
Allow your file types in .htaccess .
If you have CI installed outside of your public http web folder, you will not be able to access your images directory through a browser due to server permissions. One way around this would be to create a controller to fetch and serve the image file.
I'm using OpenSuse 12.2 now. To learn and test PHP code I use public_html directory in my home folder: /home/wojtek/public_html/ I access project files in the following way:
http://localhost/~wojtek/projects/foo/bar.php
But I have not clue how to make move_uploaded_file to work. The server root is /srv/www. I set upload_tmp_dir to /srv/www/tmp (I have really no idea where it should go).
When I set destination of move_upladed_file to /srv/www/images, files landed there. But I'd like to make use of public_html folder as I'm keeping all my files there.
For example having:
public_html/projects/foo/
public_html/projects/foo/bar.php
public_html/projects/foo/images/baz.jpg
Can I somehow use the relative destination ('images/') of move_uploaded_file in the bar.php? So that I can access images relatively in IMG tag like from bar.php?
Sorry if it sounds a bit chaotic but I'm new to PHP.
No you wont be able to access the /srv/www/images folder from the /home/wojtek/public_html/projects/foo/bar.php web page.
Id suggest either
1) setting the move_uploaded_file to /home/wojtek/public_html/projects/foo/images
or
2) using a symbolic link to access the images folder from your public_html folder:
cd /home/wojtek/public_html/projects/foo
ln -s /srv/www/images/
and then it will appear that the images are stored in /home/wojtek/public_html/projects/foo/images, but they will actually still be here /srv/www/images
Its possible that you may run into trouble with permissions using this method however