PHP - Subdomain Index.php Getting File From Entire Sites Root Folder W/o Absolute Path
I was wondering of it was possible to have a file say style.css in the root folder of a site like www.example.com/style.css and then get a subdomain called www.sub.example.com which points to www.example.com/subarea to get that file without the use of absolute paths?
Sorry if its not clear. Similar TutorialsSuppose, i have created a sub.domain.com and i want to include a file 'config.php' from root directory i.e domain.com . While i tried include("../config.php"); i wasn't successful. Anyone can help me please?? I need the solution very urgently, so please help me soon. pracasify@yahoo.com facebook.com/agptj Given a directory - folder1/subfolder1, I would like to loop through all subdirectories under the given directory and return the file path relative to the given directory. Example: Code: [Select] Given Directory FolderA FolderB SubFolderA SubFolderB SubSubFolderA File1 FolderC the file path for File1 should be FolderB/SubFolderB/SubSubFolderA/ Any ideas? hey guys im still having a issue with using the root path when requiring external files. So i can use one path and never have to worry about this issue. require("/functions/function_battle.php"); the file is located here Code: [Select] C:\Software\XAMPP\xampp\htdocs\System_Lords\functions\function_battle.php i dont understand (include_path='.;C:\Software\XAMPP\xampp\php\PEAR') im suppose to be including the php folder or something? Code: [Select] Fatal error: require() [function.require]: Failed opening required '/functions/function_battle.php' (include_path='.;C:\Software\XAMPP\xampp\php\PEAR') in C:\Software\XAMPP\xampp\htdocs\System_Lords\include\battle.php on line 2 Hi, I want to get root path and use on links even if i'm in sub to sub folder etc... suppose my site name is fitness.com and having two subfolder. so url will become http://www.fitness.com/dir/dir_sub here i want to put a link to go to root directory file. there are different ways to do that. e.g: Code: [Select] <a href='../../filename.php'>go to that page</a> but i want to use some constant that always shows to root directory. as i defined here Code: [Select] define("SERVER_NAME" , $_SERVER['HTTP_HOST']); //and used it like this <a href='<?php echo SERVER_NAME; ?>/filename.php'>go to that page</a> it works when we're on root directory. but when we go to sub directory it added sub directory name with it. which i don't want. is there any way? Thanks Hi, I have a dynamic variable like this: /def/g/qaz/pol/cxz/cba/abc I only wish to keep this: /def/g/qaz/pol/cxz How would I do this? Thanks, - mme im using this script to upload files i want to use it inside an iframe but get an error it looks like a path to root issue it works fine with no errors NOt in an iframe Code: [Select] if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'; // $fileTypes = str_replace('*.','',$_REQUEST['fileext']); // $fileTypes = str_replace(';','|',$fileTypes); // $typesArray = split('\|',$fileTypes); // $fileParts = pathinfo($_FILES['Filedata']['name']); $tempName = $_FILES['Filedata']['name']; //$tempNameEnd = explode('.',$tempName); //$tempNameEnd = $tempNameEnd[1]; $tempName = basename($tempName); if (isset($_POST['apartmentID']) && is_numeric($_POST['apartmentID'])) { $tempName = $_POST['apartmentID'].'-'.rand(0,999999).'-'.$tempName; //.$tempNameEnd; } else { $tempName = rand(0,999999).'-'.$tempName; //.$tempNameEnd; } $targetFile = str_replace('//','/',$targetPath) . $tempName; // if (in_array($fileParts['extension'],$typesArray)) { // Uncomment the following line if you want to make the directory if it doesn't exist // mkdir(str_replace('//','/',$targetPath), 0755, true); $dbTargetFile = $targetFile; $targetFile = '/srv/disk1/744444/www/example.com'.$targetFile; $success = move_uploaded_file($tempFile,$targetFile); echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile); if (isset($_POST['apartmentID']) && is_numeric($_POST['apartmentID'])) { $query = 'INSERT INTO images SET ID = \''.mysql_real_escape_string($_POST['apartmentID']).'\', ImageURL = \''.$dbTargetFile.'\', InternalSupplierID = \'100\''; fwrite($fp,$query.PHP_EOL); mysql_query($query); fwrite($fp,var_export(mysql_error(),true).PHP_EOL); //security risk!! :O //can only fix if we change image uploading script $query = 'UPDATE apartments SET mainImage = \''.$dbTargetFile.'\' WHERE ID = \''.mysql_real_escape_string($_POST['apartmentID']).'\''; mysql_query($query); } // } else { // echo 'Invalid file type.'; // } } fclose($fp); ?> I need to find a way to resolve a relative path outside the document root, in a cross-platform friendly manner. My users have a settings page where they are able to set the path to a folder where files should be included. This path may not exist at the time of saving the setting. The given path is then retrieved from the database when files are being saved, the path is checked to see if a folder needs to be created, and the file is saved to the path. Two possible paths they may use a * files (This is the webpath: http://site.com/files or absolute path /home/user/public_html/files) * ../files (This is the absolute path: /home/user/files where the webroot is /home/user/public_html/) The first path is easy to deal with. However, I'm having a rough time resolving the second path into a usable system path (i.e. /home/user/files). This needs to be cross platform compatible (windows/'Nix). I've played around with realpath(), but I'm just not finding something that works for me. Any suggestions? Hi all, I have two PHP files, one in root and the other in a folder called admin. If I set $_SESSION in a file in the admin folder and then view $_SESSION in any other file within the admin folder, everything is OK. However, if I then go to a file in root $_SESSION is blank, and it is blank if I then go back to a file in admin. This problem only exists on my hosting and doesn't happen on a local dev machine. I've compared the php.ini session settings and there both the same. Any ideas? Files admin/test.php <?php session_start(); if( empty($_SESSION) ) { echo "Session not set<br />"; $_SESSION['test'] = "test"; } echo "<pre>";var_dump($_SESSION);echo "</pre>"; /test.php <?php session_start(); echo "<pre>";var_dump($_SESSION);echo "</pre>"; Because I have include files in a subdirectory called "incl", I cannot rely on using relative paths because that include file is in a header on and the pages are in multiple subdirectories (or in the root). I need some way to get the location of the root (the one where my index file is located). I want to use something like this: $path= $_SERVER['DOCUMENT_ROOT']; include $path."/subdirectory/file.php"; However, when I use $_SERVER['DOCUMENT_ROOT'] I get : /home/content/j/p/f/name55/html/ which is not where the index file sits. Any ideas on how to get the directory where my index file sits? (i.e. the index that gets read when you got to www.domain.com) This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=308276.0 I need to assign my current folder path to a variable. I keep getting this:- Quote/var/www/html/LifeSaverHTML/Details/20 What I want is this:- Quote/LifeSaverHTML/Details/20 That full path does weird stuff. Sometimes when I'm editing files, it's like I'm editing a ghost copy but not the actual file... Weird anyways. Below is some of the attempts I've tried... If I use this command:- //$uri = $_SERVER['REQUEST_URI']; It will give me what I need but with index.php tacked onto the end:- Quote/LifeSaverHTML/Details/20/index.php <?php //$pa = $_SERVER['PATH_TRANSLATED']; //echo $pa; //$uri = string dirname ( $path ); //echo $uri; //$ echo $PWD // current directory // current directory //echo getcwd() . "\n"; //chdir('cvs'); // current directory //echo getcwd() . "\n"; //$pa = basename(__DIR__); //echo $pa; //$pa = dirname(__FILE__); //echo $pa; $cur_dir = explode('\\', getcwd()); echo $cur_dir[count($cur_dir)-1]; ?> This first one returns a blank page without error, there's one that will return just the directory most are the www stuff. I suppose I could edit the string but surely there must be a function? I am using some free code on my website to upload images but having difficulty changing the settings.
$destination_folder = './uploads/';The above file is in /public_html/page/ and saves the pictures to /public_html/page/uploads/ How can I change the destination folder to /public_html/pictures/ I have tried a few obvious things such as '../pictures/' Any ideas? Thanks, For the includes I use the following:
include($_SERVER['DOCUMENT_ROOT'] . "/cms/includes/connection.php");And for these following examples I use "http://localhost/": <img class="header_image" src="http://localhost/cms/assets/image/capture.png" /> <script type="text/javascript" src="http://localhost/cms/jquery/jquery.js"></script> <link rel="stylesheet" type="text/css" href="http://localhost/cms/assets/style.css" />With these examples I use "http://localhost/" because "$_SERVER['DOCUMENT_ROOT']" is not working with these above. My Question: Is there a function I could be using and replace it with "http://localhost/"? I am looking to have it like following: When I upload the web app onto the web server it still should be working out. EDIT: "Un-linking" those links which happen did not work. Edited by glassfish, 29 October 2014 - 06:46 AM. In the file "secure/checkout.php" I have... Code: [Select] <?php require_once "../config.inc.php"; ?> which is Relative. Can I use an Absolute Path instead?? Debbie I'm working on an email template system where my client will go to a page and copy & paste the source code into their crm system. I'm trying to find a way to automatically replace the image path without the use of echo if possible. I've figured this out already with this script: Code: [Select] <? function GetFileDir($php_self){ $filename = explode("/", $php_self); // THIS WILL BREAK DOWN THE PATH INTO AN ARRAY for( $i = 0; $i < (count($filename) - 1); ++$i ) { $filename2 .= $filename[$i].'/'; } return $filename2; } ?> But I don't wanna have to go in and put Code: [Select] <?php echo GetFileDir("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?> before all the image paths. So basically anywhere that src="images/whatever.jpg" is listed it will replace "images/" with "http://www.mydomain.com/images/whatever.jpg" is it possible to do this without having to place code before "images" ? I found one post that related to this topic but I want to make sure I understand. If I have a site with the structu /root/ ____pageone.php ____common/ ___________base.php ___________header.php ____inc/ ______constants.inc.php ____admin/ _________login.php and base.php includes: <?php // Include site constants include_once "../inc/constants.inc.php"; ?> and login.php includes: <?php include_once "../common/base.php"; $pageTitle = "Log in"; include_once "../common/header.php"; ?> and pageone.php includes: Code: [Select] <?php include_once "common/base.php"; $pageTitle = "Page One"; include_once "common/header.php"; ?>the login page loads normally, but pageone.php is broken; I get error messages like Quote Warning: include_once(../inc/constants.inc.php) [function.include-once]: failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/rootdirectory/common/base.php on line 10 . From what I understand, PHP doesn't want to include the same files from different relative paths; you either need to use absolute paths or change the directory structure so that the included files are accessed through the exact same relative path. Is this correct? I find that if I move pageone.php to the admin folder and make the relative path the same, it does work. I have to say, I'm leery of using absolute paths; and if I'm understanding this correctly, you're really constrained on how you set up your directory structure. Comments? due to mod_rewrite flaws, i have to give everything an absolute path. somehow though, the stylesheet's absolute path wont work. heres the code: <link href="C:/xampp/htdocs/lso/style.css" rel="stylesheet" type="text/css" /> the stylesheet is in the lso folder, yet somehow this wont work and no styles are loaded! PHP 5.3 on Windows 7 running IIS 7 Hey... when using: Code: [Select] $dom = DOMDocument::load( 'p:\\WebTest\\test1.xml' );where P:\ is a mapped drive, I'm getting: Code: [Select] Warning: DOMDocument::load(): I/O warning : failed to load external entity "file:///p:/WebTest/test1.xml" in ... I've also tried using / instead of \\. If it's on c:\, it works fine, but I can't get the absolute path to work to a mapped drive. If I use \\\ip\\folder\\file (or //ip/folder/file) the page never loads. Any thoughts on getting DOMDocument to look at a shared network location on Windows? Thanks! Hi! So I'm working for someone, and they want me to fix this error in a PHP file.. Here is the code: <?php include_once('config.php'); $online = mysql_query("SELECT * FROM bots WHERE status LIKE 'Online'"); $offline = mysql_query("SELECT * FROM bots WHERE status LIKE 'Offline'"); $dead = mysql_query("SELECT * FROM bots WHERE status LIKE 'Dead'"); $admintrue = mysql_query("SELECT * FROM bots WHERE admin LIKE 'True'"); $adminfalse = mysql_query("SELECT * FROM bots WHERE admin LIKE 'False'"); $windows8 = mysql_query("SELECT * FROM bots WHERE so LIKE '%8%'"); $windows7 = mysql_query("SELECT * FROM bots WHERE so LIKE '%7%'"); $windowsvista = mysql_query("SELECT * FROM bots WHERE so LIKE '%vista%'"); $windowsxp = mysql_query("SELECT * FROM bots WHERE so LIKE '%xp%'"); $unknown = mysql_query("SELECT * FROM bots WHERE so LIKE 'Unknown'"); $totalbots = mysql_num_rows(mysql_query("SELECT * FROM bots")); $onlinecount = 0; $offlinecount = 0; $deadcount = 0; $admintruecount = 0; $adminfalsecount = 0; $windows8count = 0; $windows7count = 0; $windowsvistacount = 0; $windowsxpcount = 0; $unknowncount = 0; while($row = mysql_fetch_array($online)){ $onlinecount++; } while($row = mysql_fetch_array($offline)){ $offlinecount++; } while($row = mysql_fetch_array($dead)){ $deadcount++; } while($row = mysql_fetch_array($admintrue)){ $admintruecount++; } while($row = mysql_fetch_array($adminfalse)){ $adminfalsecount++; } while($row = mysql_fetch_array($windows8)){ $windows8count++; } while($row = mysql_fetch_array($windows7)){ $windows7count++; } while($row = mysql_fetch_array($windowsvista)){ $windowsvistacount++; } while($row = mysql_fetch_array($windowsxp)){ $windowsxpcount++; } while($row = mysql_fetch_array($unknown)){ $unknowncount++; } $statustotal = $onlinecount + $offlinecount + $deadcount; $admintotal = $admintruecount + $adminfalsecount; $sototal = $windows7count + $windowsvistacount + $windowsxpcount + $unknowncount; ?> Can anyone tell me the error here, can how to fix it? I'm making an admin so I need to be able to do this: https://admin.mysite.com Run an upload image script from a file, saves image to folder in http://www.mysite.com Image Folder |