How to find Joomla root directory - joomla

how to I find out the Joomla root directory to use in files? I tried the following with no luck:
$path = JPATH_COMPONENT;
//Gives component root
$path = JURI::root();
//Gives absolute path, can't be used for some reason (http://www.site.com)
$path = $_SERVER['DOCUMENT_ROOT'];
//Gives public_html folder, but if someone installs joomla in a directory and not in root, it wrecks the whole thing
Is there a way to find the joomla root of the site only? Thanks.

may be this can help you
http://docs.joomla.org/Constants

Let's say you want to include an image from the images folder, you can simply use this:
$image = JUri::root() . 'images/image_name.png';
JUri::root() and both JUri::site() always define the root directory

Related

Laravel File not found at path (again)

So, I've already dug through the questions here about this, but still can't seem to figure it out.
Do you know what I am doing wrong here?
$imageName = $thishire->color_image;
$path = public_path('/img/colorImages/' . $imageName);
$file = Storage::get(public_path('/img/colorImages/'. $imageName));
$file->move($path, public_path('/img/uploads'));
The 3rd line is throwing an error:
"File not found at path: Applications/MAMP/htdocs/GT Laravel/public/img/colorImages/l18Ow1uVBqhReGqW7lWjanp2vT5bOAKt8pylnmmb.jpg"
But that is the correct path, so I'm super confused.
You shouldn't do Storage::get(public_path('/img/colorImages/'. $imageName)).
Storage::get() is relative to the storage disk root.
If you use the default storage configuration, then your storage root path is storage_path('app'), said otherwise /path/to/your/project/storage/app.
This is what's happening:
Storage::get(public_path('/img/colorImages/'. $imageName));
// looking into /path/to/your/project/storage/app/path/to/your/project/public/img/colorImages
// which is obviously wrong
What you should do instead:
Store your public files in the storage/app/public directory
Use the php artisan storage:link command to create a symlink between public and storage/app/public. If you are not familiar with this concept, it'll create a small file into your public directory which is a shortcut to the storage/app/public directory. More about this here: https://laravel.com/docs/8.x/filesystem#the-public-disk
For instance, with a file named helloworld.jpg and located in storage/app/public/users/8/helloworld.jpg, you can get it by doing:
Storage::disk('public')->get('users/8/helloworld.jpg');
// or Storage::get('public/users/8/helloworld.jpg');
I know it can be confusing at first. This is a quick tip to "know where you are and what your are looking at". Use Storage::path():
dd(Storage::path(public_path('/img/colorImages/'. $imageName)));
// you'll see the problem
don't forget public meaning access storage but by created symlink
I think you should be store image in your path before getting it by using
Storage::put(public_path('/img/colorImages/'), $imageName);
and you can check documentation from here
I solved it.
$imageName = $thishire->color_image;
$old = public_path('/img/colorImages/'.$imageName);
$new = public_path('/img/uploads/'.$imageName);
rename($old, $new);

Laravel uploading a file to the right directory

I upload the files alright. Only it turns out that, in my case, the starting directory is Public, and that results that the files are accesible by everybody when they should be in the directories that are protected by previous authentication, that is, under App.
So, when I do this:
$file = Input::file('fichero');
$destinationPath = 'uploads/folder';
$file->move($destinationPath);
// Create model
$model = new Model;
$model->filename = $file->getClientOriginalName();
$model->destinationPath = $destinationPath;
The file is saved in here: localh.../myweb/public/
and that is outside the App parent folder where all my application files are.
I can imagine that the fact that is going to that directory is because it is taking the default in the configuration file, which is localhost/laravel/public/index.php/
so, writing something like
$file->move(base_path().'/uploadfolder/subdirectory/', $newname);
will start from what is fixed as base_path, but the base_path needs to be something like localhost/mywebname/public.
So, how do you write the path so that it goes to directories under App and not under Public?
I hope I am not asking a dumb question, but I have been trying for days and I have read the 3 related queries in here.
thank you
You may use:
app_path() // Path to the 'app' folder
app_path('controllers/admin') // Path to the 'app/controllers/admin' folder
This will return you local file system path, you should put your uploaded images in public/... folder.

What is the '.' directory in Windows?

For example, a directory has the following files: (as shown in explorer)
index.php
hello.php
img
If you query it using windows or just type dir in cmd prompt it will have the following files:
.
..
index.php
hello.php
img
I understand that '..' is a link to the previous directory, but what exactly is '.' and how can it be used? I've searched all over the internet, but no avail found for the single dot
The . can be used in some commands: This will copy the files from c:\temp to the current directory:
copy c:\temp\*.* .
The .. can be used to move to a higher directory.
This will change to the parent folder:
cd ..
The '.' indicates the current directory as per this. As you mentioned, '..' is a link to the previous directory. Ultimately the Operating System will choose how to indicate these, but it is pretty standard across all major OSs
. is the same as the current directory, but in a relative way.
For instance if the current directory is c:\temp and if you cd in this directory, then . == c:\temp.
In short . is the current directory and .. is the parent directory. It is convenient for you to write scripts with these keyword otherwise you have to write a long command.

How to get public directory?

I am a beginner here so pardon me for this question am using return File::put($path , $data); to create a file in public folder on Laravel. I used this piece of code from controller I need to know the value of $path how should it be.
Use public_path()
For reference:
// Path to the project's root folder
echo base_path();
// Path to the 'app' folder
echo app_path();
// Path to the 'public' folder
echo public_path();
// Path to the 'storage' folder
echo storage_path();
// Path to the 'storage/app' folder
echo storage_path('app');
You can use base_path() to get the base of your application - and then just add your public folder to that:
$path = base_path().'/public';
return File::put($path , $data)
Note: Be very careful about allowing people to upload files into your root of public_html. If they upload their own index.php file, they will take over your site.
I know this is a little late, but if someone else comes across this looking, you can now use public_path(); in Laravel 4, it has been added to the helper.php file in the support folder see here.
The best way to retrieve your public folder path from your Laravel config is the function:
$myPublicFolder = public_path();
$savePath = $mypublicPath."enter_path_to_save";
$path = $savePath."filename.ext";
return File::put($path , $data);
There is no need to have all the variables, but this is just for a demonstrative purpose.
Hope this helps,
GRnGC
I think what you are looking for is asset(''); You can use asset('storage'), after creating your symbolic link.
asset('public')
OR
url('public')

Carabiner: cache path does not exist. Please set the cache path in config/carabiner.php

I am using code iginiter. When I try running my application from a local browser then this error is throwing up.
Carabiner: cache path does not exist. Please set the cache path in config/carabiner.php.
I have no clue what it is. Tried some online similar solutions like :
http://www.webdevelopersdiary.com/1/archives/06-2012/1.html
but for some reason nothing seems to work. Please help me to come out of this.
Create cache directory specified in config/carabiner.php, at line #50.
Default setting: $config['cache_dir'] = 'assets/cache/';
Remember that cache_dir path is relative to document root (aka FCPATH from CI ; where index.php is located). On initialization, FCPATH and cache_dir are concatenated, resulting cache_path.
Excerpt from library:
$this->cache_path = $this->fcpath.$this->cache_dir;
Update
You need to create assets/cache directory, which is located in you application root, with write permissions: mkdir -p assets/cache && chmod -R 777 assets/cache
In the end, it will look like this:
$ tree
.
|____application
|____assets
| |____cache
|____index.php
|____system
|____user_guide

Resources