Nested codeigniter and how to get relative path of main codeigniter folder - php

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.

Related

Configure nginx to use files and folders with the same name

I am taking over a website from a sister company and their site has several places where a folder will have a sub folder and a .php file with the same name. For example, the parts folder will have a store folder that contains several more files and folders but it contains a store.php file as well. nginx is throwing a forbidden error because it thinks the user is trying to list the folder directory but the url /parts/store/ should show the store.php file and still allow the user to go to /parts/store/category/product and should show a product file nested in the parts/store/ sub folders.
One option would be to rename the files you want to be directory index as indes.php if your Nginx configuration allows for that. That in my mind is the simplest solution and is most inline with web standards.

I can' upload file on my shared folder using laravel

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

MVC - CSS links

I am relatively new to this whole MVC structure for web apps.
Here is the structure of my project.
The file you see on the right of the picture is inside the 'Views' folder.
When I want to link a css file, why does the path have to be href="/css/stylePortfolio.css"
Why is it not href="../../public/css/stylePortfolio.css"?
What you are looking at, is the HTML that is sent to the users' browser. The browser does not know anything about the structure of your application. It simply reads that href link, and downloads the file from http://example.com<link>, where <link> is /css/main.css for example.
When configured correctly, the web root of your website is in your /public folder. That means, anything that a browser requests, is relative to your web root. Thus, if you want to link to a css file, you need to think of that link relatively to your projects web root, not relatively to your project root.
An example:
Say, you create a new project in /home/user/AwesomePhpProject.
Now, /home/user/AwesomePhpProject is called your project root.
In your project root, you create a directory, public. You configure that directory to be your web root, using VirtualHost (when using Apache) or the root directive (when using Nginx).
/home/user/AwesomePhpProject/public is now your web root.
When a browser requests /css/main.css, it will be directed to /css/main.css relative to your web root. In our case, that will be /home/user/AwesomePhpProject/public/css/main.css.
Most modern applications separate the project and web root, for security reasons.
As your index.php is inside the public folder, so all the views are loading in the public folder. That is why you should declare the CSS path from the public root. You can modify the path if necessary.
In this case, you can declare a global variable or constant your main controller with the path of your CSS folder
define('CSS_PATH', 'http://localhost/fab/public/css/');
Now use this like
<link rel="stylesheet" href="<?=CSS_PATH?>bootstrap.css">
It's because front-end links (like CSS and JS) are relative from current file you are in. And since your root is in public you have to specify URL from this directory (you can't link to any file in top level of root).
Why is it not href="../../public/css/stylePortfolio.css"?
Because entry point of your MVC is index.php from public folder. So all your css and js links should be relative to public folder

Some of the directories are accessible from public URL. How to avoid this in yii

In my Yii web application some of the directories are accessible from the public URL (main directory or application folder) like js, css, images etc. How to avoid this problem. This is a major security issue, but I don't know how to fix this. Please help me...
Thanks in advance...
If you're using Apache, you can restrict access to directories doing the following:
Create a .htaccess file in your directory so path/to/directory/to/deny/.htaccess
Open .htaccess and add Deny from all
You have to turn of apache directory listing. Use the link below.
How do I disable directory browsing?
Then change all files and folders permissions of a directory to 644 and 755.
Change all files and folders permissions of a directory to 644/755
Let me know if you need help
Here is some instructions given in documentation.
1) It's important that the directory be writable by the webserver user so that Yii can publish the resources there when needed.
2) When a project has multiple versions (production, testing, development, etc.) do not copy the assets/ folders from one area to another; allow Yii to deploy them automatically in each area.
3) Do not manually edit any file under assets/ - if you have a real need to make a change, find the publishing module, edit the source, delete the subfolder under assets/, and let Yii re-publish the updated files.
4) Do not reference names under the assets/ folder directly (say, to get at some other module's assets). If you need to use that
5) Do not add the contents of the assets/ folder to any source-code control system; these files have master source in other places.
6) It is safe to delete everything under assets/. Yii will re-publish the assets if they are not found under assets/.
Hope it will help you :)

Restrict PHP files outside application folder in CodeIgniter?

How can I restrict PHP files from getting executed outside the application folder?
I am using CodeIgniter and I have heard it somewhere that this thing is possible in CodeIgniter.
Temporary, I have added request in htacess which will surpass each request from index file and will result in not found.
Add public folder, move index.php into it, inside index.php change application and system folder settings to ../application and ../system respectively. Point domain to public folder.

Categories