have a website that is obviously in the root of my server. I am now making a web app, which lies in m/iphone/. All was going well but my website uses scandir() with all of the files in a folder on the root of my server.
How can I access these files from when I'm inside the m/iphone directory?
Sorry if it's a really obvious answer, I'm a complete beginner.
Thanks in advance for any help
You have to use .. which stands for back in terms of folders, in your case you should run something like this:
scandir(dirname(__DIR__));
You should play with .. in path name:
scandir(dirname(__FILE__).'../anotherfolder'); //go back one folder and go to folder 'anotherfolder'
Hope it helps.
Related
Okay so I don't know if this is a "can't see the forest for the trees" situation but I'm slowly losing my patience on this.
All I want to do is find a way to include files from the project's root, no matter how nested the file, no matter where it's all hosted.
I obviously can't just do absolute paths like "/includes/file.php".
I can't use $_SERVER['DOCUMENT_ROOT'] because, as far as the servers where I'm hosting it are concerned, that's the wrong path.
I read about creating a config.php file in the root directory and defining the ROOT_DIR there, but that means I have to include that file RELATIVE in every script, which makes things unstable again. (I don't want every include to break because I moved the file somewhere else)
I can't use constants like DIR because it returns the current directory, not the absolute project root.
I tried to set the include path, which doesn't seem to work.
The only "solution" that works for me as of right now: In every file, I define a $root variable and set it to the path that I know is the correct project root.
That can't possibly be the best solution, can it?
There must be an easier way. And the fact that I can't find it drives me crazy.
The root path that works looks something like this:
"/mnt/web10145/dd3/519/5878104319/htdocs/project" (numbers changed)
Using this for includes works just fine. However, calling set_include_path($path) and then including without that path doesn't work.
Please, if anyone knows anything: Every answer is deeply appreciated.
Don't mind pointing out how stupid I am to not have thought about xyz. If it helps me solve the problem it's all good.
Thank you!
I'm developing a website in PHP.
The test environment is in a subdirectory of the root and there are multiple test environments. But the website doesn't work properly because of al the absolute and also the relative paths.
So i need a clean solution to get the path of the root of the website and not of the server.
I've tried a lot of thinks but nothing seems to work.
I hope you have a beter solution for this problem.
Thanks in advance!
Not sure if this will help, but if you want to get directory of current php file you should use __DIR__ constant. More info here.
If your website index is located at /home/www/subpath/index.php, this code in index.php:
echo __DIR__;
will return:
/var/www/subpath
You can use a SESSION to set your desired PATH and use it on all the path you need.
If you are using a framework like Laravel this can be done a lot easier.
Hi here I was openshift novice users, where before I used the cpanel for my hosting, and I want to switch to openshift, that I ask is how do I change the document root?, if previously on cpanel is Home/public_html/thelifestylelist.com to Home/public_html/thelifestylelist.com/public on openshift? (my index php is on public directory)
Hopefully the picture below can clarify my question.
Thank you.
Sorry i used external link for my image, need at least 15 reputation to attach image. .
This is the order OpenShift search for root directory
IF php/ dir exists THEN DocumentRoot=php/
ELSE IF public/ dir exists THEN DocumentRoot=public/
ELSE IF public_html/ dir exists THEN DocumentRoot=public_html/
ELSE IF web/ dir exists THEN DocumentRoot=web/
ELSE IF www/ dir exists THEN DocumentRoot=www/
ELSE DocumentRoot=/
So you just add the any of this folders.
According to this blog post, there are multiple document roots you can use for your PHP project (or static html project), you can read it here: https://www.openshift.com/blogs/openshift-online-march-2014-release-blog. Since you are using open shift, it would probably be best to just use the document root they provide you by using git to download/upload your files to your gear. You might review this page to help you get started: https://www.openshift.com/get-started
I got a plugin online(fancyupload), trying to upload multiple file to different folders. first I created the folders using mkdir() then passed the folder name to a session id both in the index.php file as well as the script.php file, but I discovered the script.php file doesn't see the session and it uploads the files directly to the uploadedfiles folder. can anyone help as I have tried everything possible. I am new to stackoverflow( although been reading on issues here for a while) so really don't know the rules here.
Thank you in advance
index.php
<?php
session_start();
mkdir("C:/softwares/wamp/www/Emma/uploadedfiles/".$_POST['directory']."/");
$_SESSION['directory'] = $_POST['directory'];
Script.php
move_uploaded_file($_FILES['photoupload']['tmp_name'], "uploadedfiles/".$_SESSION['directory']."/".$_FILES['photoupload']['name']);
chmod("uploadedfiles/".$_SESSION['directory']."/".$_FILES['photoupload']['name'], 0777);
Sorry for the question, I have solved the problem, it was quite easy was just thinking in one direction!!! Thanks anyways viewers
E.g:
local drive C:
folder1 346MB
folder2 567MB
....
file1 345MB
file2 343MB
....
Because I have thousands of folder or files in the local drives , and I want it to display in the web page and remove them from the web page base on their total access times . and the folders or files which have no access will be deleted!So is it a good way to do that or have others much better!?
Any idea would help!!
[update]
I found a windows tool to Calculate folder size from the command line .Disk Usage v1.34. It is good to return all folder and their's size. And now the question:
Which is faster.PHP or the internal command line tool!?
Thank yo very much!!
Use a shell command.
Never tried this etc. But this is more of what you are looking for. As for the deletion an access times, you will have to code it up and figure out that logic.
http://pc.byethost17.com/scripts/php/?id=12