I work in responsivefilemanager and in config file I Have two line:
$upload_dir = '/user/uploads/files/'; // path from base_url to base of upload folder (with start and final /)
$current_path = '../../../../uploads/files/'; // relative path from filemanager folder to upload folder (with final /)
This wroked In xammp system (with sub folder. /user/ is sub folder). if i move in real server i need to edit this two line and remove sub folder and one ../ from two line.
Now, I need to auto detect url path. My mean is : if i install in sub folder Or root folder this two line worked in my script without manual editing.
How do can i create this?
There is no particular way to just autodetect what directory to upload to. The easiest is to solve this by just checking if the directory exists and use the other directory if it was not found.
However, I'd suggest having the same relative structure on both systems is the best solution. With the same relative structure this should work across all servers and systems without having to change anything.
Related
Is it possible to include file from the ftp's root in a script in a subdomain ?
This doesn't work for me:
include($_SERVER['DOCUMENT_ROOT'].'/joomla.php');
Can someone help me ?
I think first you need to determine where is your subdomain files are placed and echo the $_SERVER['DOCUMENT_ROOT'] command to see the full path then you can combine two paths and make necessary adjustments.
Usually but not always, subdomain files are placed in a folder one level up then the main site's root folder so you may need to replace the folder name according to your needs in the output of server document folder function.
To give an example if your domain files are in a path like
/var/www/vhosts/example.com/httpdocs/
and if your subdomain path is like
/var/www/vhosts/example.com/subdomain/
then you will need to replace httpdocs with subdomain (or the other way around) in the output where you call $_SERVER['DOCUMENT_ROOT']
Okay so I'm learning about uploads and need to copy the tmp file to a specified directory so I use the copy command.
I use this inside my index.php of the main directory (learningupload/ folder)
copy($_FILES['photo']['tmp_name']['file'], './pics/'.$photoname.'.jpg');
Now I'm doing this on Xampp local host, and my uploads go to the tmp folder which is of course different from where I want the upload to go
so there's
C:\xampp\tmp
C:\xampp\htdocs\learningupload\pics\
My question is this: What is this ./ inside the destination string I need to have? Doesn't it usually mean you're moving UP a directory? Why not have it '/pics' no dot? I tried that and said it couldn't open the stream. Does the dot here mean it's referring to whatever directory index.php is in? Or am I thinking ../ moves up a directory? And single dot is different?
Thanks.
./ means "current working directory". Which directory is current working one you can see with echo getcwd();
The parent directory (the upper one) is ../
You can change your working directory using chdir() or you can just specify the full path instead.
I have a php function that is moving files for me. It requires absolute paths to place those files (/Applications/MAMP/HTdocs/mysite/myfolder)
how can a turn this folder path string into a url (http://mysite.com/myfolder) so that I can create links to the files on the fly?
I do not know necessarily the names of the folders, as the software could be run in many locations.
Many thanks.
Obviously, you need to know server root for such a calculation.
Luclikly, $_SERVER['DOCUMENT_ROOT'] contains this path.
So, just subtract server root path from the given path:
$path = '/Applications/MAMP/HTdocs/mysite/myfolder';
$approot = substr($path,strlen($_SERVER['DOCUMENT_ROOT']));
check if you have a drive letter in the DOCUMENT_ROOT, and correct the code if necessary
Note that adding http://mysite.com is unnecessary and useless. just /myfolder/ is what you really need.
You can check for this value: $_SERVER["DOCUMENT_ROOT"];
That is the root of your website. If you have the folder and replace the $_SERVER["DOCUMENT_ROOT"] with the $_SERVER["HTTP_HOST"] you will get the URL to the folder/file
If mysite folder is within HTdocs then you can access it using http://yourdomain/mysite, (if HTodcs is your home directory)
Let’s say I have two folders in my PHP server root directory: x and y. There are two more directories inside the x folder: a and b. In the /x/a directory I have the index.php file and in the /y folder a stuff.php file.
From my /x/a/index.php file, I want to include the /y/stuff.php file. How do I do that?
My server doesn’t allow including files from other domains, so adding the full URL doesn’t work!
Also, I’d like to know how to start a path from the root in PHP. I use ./blabla from the index of my root and ../blabla from directories in the root, but, unfortunately, .../blabla doesn’t work from 2nd grade directories.
To access the root begin your path with "/".
If you want to go up one directory from where you are currently, e.g. from /x/a/ to /x/ you could use "../".
If you want to go back up two directories (e.g. from /x/a/ to /) you could use "../../" (rather than ".../" which you mentioned).
try:
include "../../y/stuff.php";
I wanted to use a script using instant messaging and found this.
The instruction said that to Make sure that in blab_im/config.php you've set properly $site_to_bim and $bim_to_site:
$site_to_bim='localhost/ThesisDB/blab_im/'; // URL or relative path from your main site to BLAB!IM, default:> $site_to_bim='./blab_im/'; [must end > with a trailing slash]
$bim_to_site='../'; // URL or relative path from BLAB!IM to your > main site, default: $bim_to_site='../'; [must end with a > trailing slash]
i was able to understand a little bit the first part(Correct me if I am wrong)
the second part I do not understand which is bim_to_site.
Thanks/Salamat in advance!
The second variable is asking for the path to take from the directory that the im client script is in to the www root.
So, for instance if the im client is here:
www.example.com/files/imclient
that would give you:
$site_to_bim = '/files/imclient/;
$bim_to_site = '../../';
because you go up 2 levels from the im directory to the main site directory.
Update
When you are specifying a relative path, you can start a few different ways:
with a slash: /files/. That will tell the parser (or browser) to try to find the target beginning from the main directory, then into the files directory.
with simply the directory name: files/. That means begin looking where you currently are and look for the files directory. So if the script resides in the imclient directory from the above example, this would mean "look for the files directory inside the imclient directory.
with a dot slash: ./files/. This means the same as the above. Start in the current working directory.
with two dots and a slash: ../files. This means start in the current working directory and move up out of it to the parent directory. So in the example, if the script was in imclient, using ../ would say "look for things in the files directory and ../../ would say "look for things in the main directory (the parent of files).
Does that flesh it out a bit?