PHP - Function For Using Absolute Path?
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. Similar TutorialsIn 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 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? 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" ? 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! 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? 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! 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. 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? Code: [Select] header('Location: ' . $register_success); Code: [Select] $register_success = 'register_success.php'; The header function above gets executed after a successful registering, and the variable is stated in the path.php file, which gets included into the header.php file, which also is included into the page, and also into the page with the register form. The register form is contained in the path model/register/register_script.php, and the file register_success.php is in the same folder. The problem I am having is that the header function does redirect to controller/register/register_success.php this used to be the previous location of that file. I am wondering is the old path saved somewhere in the cache, and this all is actually a caching problem? It does not seem to be a caching problem of the internet browser because I cleaned the cache out. What else could be the cause for this problem? If it is a caching problem, which cache could be, as in in which location? I have configure Xampp my site is fully functional except for the error Deprecated: Function split() is deprecated in C:\Images_Database\imagesdb\htdocs\jpserver\system\frameworks\read_site_info.php on line 15 Line 15 code shown Below $sub_folders = split("/", $_SERVER["SCRIPT_NAME"]); how to split in a proper way can any one help me God Blessings Hi guys, Happy New Year http://www.phpfreaks.com/forums/php-coding-help/?action=post How can i get the path http://www.phpfreaks.com/forums thanks, In NetBeans - in what I think is the Web Root - I have... config.inc.php secure/checkout.php In "checkout.php", when I use this code it works... Code: [Select] <?php require_once "../config.inc.php"; ?> but when I try to use an Absolute Path, it errors out... Code: [Select] <?php require_once "/config.inc.php"; ?> I thought "/" moved you up to the Web Root and then you drill down from there? So the second example should also work in my mind?! What is wrong? Debbie Hey guys! I just joined this forum today, and I'm wondering about something... I see a lot of sites, and in the code of the site, style sheets and javascript includes are references in a manner similar to this... "href='http://www.somesite.com/css/css.php/someDirectory/style.css'" How is this done? The path following the "css.php" is what confuses me. Thanks for any information you have! Can I use this path? I didn't know if I could pull in images into a subdomain from another domain ../mysite.com/assets/img/avatars/defaultuser.jpg I have the folder structure like:
root
application
system
assets
uploads
folder assets contains all css, img, and js.
uploads contains user uploaded file.
I set a "helper/assets_helper.php" file to define:
define ('ASSETS_PATH', base_url().'assets/'); define ('UPLOAD_URL', base_url().'uploads/');For all the css, img, and js, it works well like href="<?php echo ASSETS_PATH; ?>css/mycss.css"But when I display the uploaded images, it couldn't display image with <a href="<?php echo UPLOAD_URL;?>images/myupload01.jpg" ><img src="<?php echo UPLOAD_URL;?>images/myupload01.jpg" /></a>This uploaded image actually works fine with my localhost with the link like: http://localhost:900.../myupload01.jpg. But it couldn't display on my hosting server with like: http://users.mywebsi.../myupload01.jpg Can anyone shed some light on it. Thanks! Edited by TFT2012, 20 October 2014 - 10:43 AM. Hey Everyone, I have these 3 scripts to upload an image but I'm having an issue because the images uploaded are going to the same directory as the pages. What do I need to change to make the uploaded images go to a folder path called "pictures". Thanks in advance for the help. Script 1 <form name="form1" method="post" action="adminpicturebrowse.php"> <p align="center">How many pictures for this dog? Max is 9</p> <p align="center"> <input name="uploadNeed" type="text" id="uploadNeed" maxlength="1"> <input type="submit" name="Submit" value="Submit"> </p> </form> Script 2 <form name="form1" enctype="multipart/form-data" method="post" action="adminaddupload.php"> <p align="center"> <? // start of dynamic form $uploadNeed = $_POST['uploadNeed']; for($x=0;$x<$uploadNeed;$x++){ ?> <input name="uploadFile<? echo $x;?>" type="file" id="uploadFile<? echo $x;?>"> </p> <div align="center"> <? // end of for loop } ?> </div> <p align="center"><input name="uploadNeed" type="hidden" value="<? echo $uploadNeed;?>"> <input type="submit" name="Submit" value="Submit"> </p> </form> Script 3 <? $uploadNeed = $_POST['uploadNeed']; // start for loop for($x=0;$x<$uploadNeed;$x++){ $file_name = $_FILES['uploadFile'. $x]['name']; // strip file_name of slashes $file_name = stripslashes($file_name); $file_name = str_replace("'","",$file_name); $copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name); // check if successfully copied if($copy){ echo "$file_name<br>"; }else{ echo "$file_name<br>"; } } // end of loop ?> Hi, How can i show image using absolute path instead of virtual path?? Help please I am trying to find the URL to a directory TWO levels above the script level (if you know what I mean). For example.. the script sits at Code: [Select] http://www.domain.com/TestArea2/members/index.php BUT I need to find the path to Code: [Select] http://www.domain.com/TestArea2/ the nearest I get is... $domain = $_SERVER['HTTP_HOST']; $domain .= $_SERVER['REQUEST_URI']; echo $domain; // outputs www.domain.com/TestArea2/members/index.php Is there a simple method to do this or have I got to split the string and work backwards? Many thanks It's the simple things that frustrate me sometimes. My project has a one root folder. Under that are three separate folders (admin, img, and inc). "admin" contains admin pages, "img" contains images, and "inc" contains utility files to be included and used by other scripts. I'll just take one specific problem as an example. In my inc folder is a file called "send_email.php". It needs to include another file called "class.phpmailer.php" in the same directory (inc). Now, since these files are never called directly but included by scripts in the rest of the project, I cannot simply do "require('class.phpmailer.php')". I have a file in the base project directory called validation.php. It needs to include inc/send_email.php to use its functions to, obviously, send email. Now, that part is no problem. I just require('inc/send_email.php') since that is a valid path from validation.php. My problem comes when send_email.php tries to include class.phpmailer.php. As I said before, I cannot just directly include it without any path since it's not being called directly. It "inherits" the path of the file that called it so just a direct require to it. My "solution" was to add a config value called "path" to my config file in the root directory. It would ideally hold the path from the server root to my project folder. In my case I set it to "/danny/smswebalerts/" which is indeed the correct path from my web root. I use $config['path'] to link to my images and CSS files and it works correctly. I thought it would solve my problem when I did the following in send_email.php: require_once($config['path'] . 'inc/class.phpmailer.php'); That indeed correctly builds the full path to that file: /danny/smswebalerts/inc/class.phpmailer.php. When I open up a page that includes send_email, however, I get the following error: Code: [Select] Warning: require_once(/danny/smswebalerts/inc/class.phpmailer.php) [function.require-once]: failed to open stream: No such file or directory in /home/danny/workspace/smswebalerts/inc/send_email.php on line 20 I would appreciate if somebody could give me some nice solution before I just say "screw it" to organization and plop everything in the same directory. It's really frustrating that my project is being held up by some technicality like this. my problem is when i click on hyperlink it start copying it self insertrow=yes in address bar how to tackle this Code: [Select] $httpquery = "{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}&insertrow=yes" ; <a href='{$httpquery}' >New</a> <br> if (isset($_GET['insertrow'])) { echo "<br> {$_GET['insertrow']} "; } |