I am trying to use AJAX to return high-level calculation results. However, it appears as though the PHP file that I am pointing the AJAX call to is in the '/' root directory. Here is a snapshot of how my structure is: c:\webserver\test\webroot (this is the root directory), and then c:\webserver\test\code is where the HTML and PHP files are stored - looking to use an AJAX call to point to a PHP file in the non-root folder (which is one folder up, then one folder down). I tried a few different things, such as '../code' to move up and then over, but that doesn't work. Any suggestions?
Referencing a file location via relative paths should work - you'll just need to be sure that you are navigating FROM the correct folder TO the correct folder.
This can be a bit tricky if your javascript file is located in another folder - if memory serves you must navigate from the folder containing the javascript file, not from the folder containing the index file.
Alternately, you can use FQDM http://example.com/folder/folder/file.php to reference the file. Note that if you are on localhost, you can use a hosts file to fake-out the webserver.
Related
I am using shared hosing for Codeigniter application for deployment.
How can i run staging url on live server?
1) domain.com (Working)
2) domain.com/staging/ (Not working, showing 404 error)
I created staging folder under public_html directory, now put All CI code in staging folder, and tried to run the application with URL domain.com/staging/ but it redirect on domain.com/404
I expect to run domain.com for users and domain.com/staging for development. (Staging URL i will use for development and after that i will place the same code for live URL.)
This is most easily done by using a subdomain for the staging version, i.e. staging.doman.com. The folder where you put the CI files isn't super important as the subdomain will be set to use the directory you choose.
You will either need to have complete control over the server or have a service provider that allows you to set up subdomains.
- Expanded Answer -
If you cannot set up a subdomain then your next best option is to use the advice in the documentation on Managing you Applications. It isn't required to use the file structure shown there. In your case try the following.
Create a folder on the same level as application named staging.
Into that folder copy all the folders and files normally found in /application.
Add all application folders and files required by your site. The files in these folders are those that make up the application you are staging.
Make a copy of index.php (the file at the root of the public folder, i.e. domain.com/index.php) and name it staging.php. Both index.php and staging.php will be in the same folder.
Edit staging.php and change the value of $application_folder to be the absolute path to the staging folder. For example:
$application_folder = '/path/to/domain.com/public_folder/staging';
The path above is an example. You must replace it with the actual path in your server. If you have no idea what the full and absolute path is you can use
$application_folder = dirname(__FILE__).'/staging';
Browse to the URL domain.com/staging.php and you should get your default controller's output. To test that you are actually seeing the staging version of the page temporarily change something in the view file so there can be no doubt.
You will go to other controllers by using the URL domain.com/staging.php/other_controller.
Change the value of $config['index_page'] in /staging/config/config.php to staging.php, e.g.
$config['index_page'] = 'staging.php';
Without the above change redirect() and many other "helper" functions will not work correctly.
(Optional?) You can probably edit the main .htaccess and add rewrite rules for staging.php the same way it is done for index.php. But I will leave that as an exercise for you. (Or for another SO question.)
A final word. It might be necessary to make other configuration changes to accommodate the revised file structure. I tested the answer here but did not go beyond the most basic task of browsing to controllers. Most likely config values for sessions, cookies, and many others will need to be adjusted for the staged version to work correctly. Check out the documentation on Handling Multiple Environments for guidance on making this less painful.
It appears that this question is asked often and answered the same way: store the css files outside of the application directory and then use base_url() . "path/to/file".
However, I want to keep my css files and js files inside my application/views/ directory, because the views directory is effectively the html space, and css and js belong to that space (in my opinion).
Below is the structure that I wish for:
root
- application
-- views
--- assets
---- css
---- js
- system
When I attempt to load css files from within this directory structure, I get a NetworkError: 403 Forbidden, which makes sense because of CI's framework protocol.
But I am guessing that there is a way.
Publicly reachable files like CSSes images and JS files need to be in public directory next to index.php file. So hierarchy would be:
root
- application
- system
- assets
-- css
-- js
You can aproach to those files with hard coded
Link
or using (loaded) url helper with it's function base_url() or site_url(). Don't forget to fill correct URL into application config file.
Link
Docs.
Hey i'm going to politely push back on this idea :-)
Your application and system folders should be ABOVE the root, so they are not publicly accessible. (Unless this is a really simple application and you are not doing any database interaction, etc). They should not be considered part of the HTML or public space because you do not want the public accessing them. Set the path for them once in the main index.php file and its done.
Also i suggest renaming your system and application folders, like "system302". Over the long term it makes versioning and upgrading (and reverting if needed) much easier.
I have some forms that allow the user to upload files that only they can view so I will have to store them somewhere. However, I haven't been able to find any information about where these files would usually be stored if I want them to be kept on the local server. Therefore I have to assume that there is no convention for the permanent storage location of uploaded files. Am I correct in this assumption?
To be clear, I'm not talking about temporary storage locations.
Additionally, would it be a bad idea to have the storage location of all the files as a subfolder of the app directory (with gitignore enabled on it)? Or would it be a better idea to have it outside of the app folder? Thanks!
There is no explicit convention on where to store user uploaded files.
However Laravel ships with a storage directory where it stores framework related data such as cache, sessions, etc. As the name denotes it's a good place to store files, not just framework files. Also the Laravel Filesystem Documentation mentions that the default configured location is storage/app (but that can be changed to fit your needs):
When using the local driver, note that all file operations are relative to the root directory defined in your configuration file. By default, this value is set to the storage/app directory. Therefore, the following method would store a file in storage/app/file.txt: Storage::disk('local')->put('file.txt', 'Contents');
This storage/app folder will by default be ignored by Git.
If you also need the files to be publicly available, then you have two options:
1. Store them somewhere in the public directory.
2. Store them in the storage directory as suggested above and create a symbolic link to the folder from a public location. On Linux you can run this:
ln -s /path/to/laravel/public/files /path/to/laravel/storage/app/files
Of course the directory names can be whatever you like, I used files as an example.
The first option is for cases where you don't have shell access or are otherwise unable to create symbolic links. So if possible I suggest you use the second option.
Laravel uploads to the temporary file path, then you will have to move the file:
$request->file('photo')->move($destinationPath);
This method will move the file from its temporary upload location (as determined by your PHP configuration) to a more permanent destination of your choosing.
SOURCE: https://laravel.com/docs/master/requests#files
I have another system that will drop in a data.json file somewhere onto my Laravel site/folder structure.
I want only Laravel to be able to be able to read the json file (i.e. a user can't see it by typing a url into a browser).
Where should this file go?
I'm currently torn between putting it in application/models folder or application/[new folder]. My webroot is set to the public folder, so you can't access the application folder via a browser.
If it is in there, I'm assuming I will be able to read it within php but not javascript (which is okay).
Just create a new folder in the app/ directory. Thats not visible to outsiders. Everything visible is in the public folder, as you said. If you create a new folder you can autoload it by setting up composer.json.
I have directories under my controller directory that serve perfectly. However, creating any new directories on that level results in a 404 every single time. All I am doing is echoing hello world. I believe it is a directory issue at this point. Privileges are the same as the directories that are working as well as the files.
There is a .htaccess in the /application directory of CodeIgniter which prevents you from accessing files within that directory directly.
This is done be design so that none has direct access to your code. You should consider not deviating from this.