PHP - Moved: Relative Or Absolute?
This topic has been moved to CSS Help.
http://www.phpfreaks.com/forums/index.php?topic=345942.0 Similar TutorialsI am trying to load an xml file but I can't seem to find the location to load it. Here is the location of the xml file: C:\inetpub\wwwroot\php\webphp.xml Here is the location of the file trying to load the xml: C:\inetpub\wwwroot\php\gui\guiindex.php What location would I put in he $xml = new SimpleXMLElement("XMLFILELOCATION", NULL, true); Hi, I'm sorry if this has already been posted, a search of the forum didn't turn anything up so i'll ask away. I'm trying to fetch urls from a document on my server and convert them into absolute urls. I can extract them but some of my links use ../ or ./. I think i've solved the ./ one but I can't find anything on getting the url when ../ is used. As an example some urls use ../index.php when in a directory so http://www.example.com/dir/test.php, so a url of ../index.php from here would land the user on http://www.example.com/index.php. At the moment it's landing on http://www.example.com/../index.php. Any ideas? Help would be appreciated Hope this goes here. I run php5 apache 2.2 with mysql4 on my local machine I prefer relative addresses. Can someone help with the correct syntax to call... say.. the Home page (index.php) in the root directory with something like <a href="../" (../ takes me back too far) when called internally At the moment I have to stipulate eg. <a href=index.php> etc Cheers Brian 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? 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? well good moring dear folks - hope you are all right and everythings is fine across the atlantic today i have a question regarding server-paths - and the absolute and relative in a linux-[opensuse 11.4] lampp-system well i just installed something in to my Lampp on openSuse 11.4 while setting up this application - (it is a joomla 1.7.3 ) i wonder how i name the paths public $unicodeslugs = '0'; public $feed_limit = '10'; public $log_path = 'D:\\Xammp\\xampp\\htdocs\\pre1/logs'; public $tmp_path = 'D:\\Xammp\\xampp\\htdocs\\pre1/tmp'; public $lifetime = '15'; public $session_handler = 'database'; what cou you thinks how shoud i name the paths well you see above this was a windows box where the pahts originally were taken from love to hear from you ok so i am using relative timestamps on my forum. if a post was created less than 1 hour ago then it will display something like 32 minutes ago. If it was posted more than 1 hour ago it will display "posted today at 10:00pm", or if it was older than 1 day then it will display the absolute time stamp. My question is how do i get them to update automatically like facebook does? i would like to use jquery for this but after searching i cant make heads or tales of any of it. so to sumarise i would like the timestamps to update without having to refresh the page. Thanks Directory structu /home/~test/public_html/soap/ .../xml/ .../bin/ .../products/browser/ In file /home/~test/public_html/soap/bin/products/browser/test.php, I include another file and call it's function: Code: [Select] require("../../xml/processXML.php"); $xmlData = generateXML(....); In the /home/~test/public_html/soap/xml/processXML.php, I have the following code: Code: [Select] function generateXML() { exec("../bin/code.cur"); } The problem is the exec("../bin/code.cur") fails of the relative path issue. I did a getcwd() before the exec() and it returned /home/~test/public_html/soap/bin/products/browser. I have tried using dirname() and no help. I hope this is clear enought to understand where I am coming from. Thank you. AM Any thoughts on this function? Basically what it does is take the current users location ($location) and a relative path ($link) and convert it to a valid URL. I do know that this does work on my example, but does anyone have any suggestions on this? Code: [Select] <?php $location = "http://mysite.com/pages/images/docs/myfile.html"; $link = "../../games/game.html"; function resolve_url($current, $link){ $ui = (object)parse_url($current); $domain = $ui->scheme."://".$ui->host; $levelsA = preg_split("/\.\.\//", $link); $levels = 0; foreach($levelsA as $l){ if(empty($l)) $levels++; } $currentA = preg_split("/\//", $current); $length = count($currentA); array_splice($currentA, -$levels - 1); $currentA[] = preg_replace("/\.\.\//", "", $link); return implode("/", $currentA); } echo resolve_url($location, $link); ?> Thanks! 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? I'm kind of a beginner in PHP and I'm not sure how complicated is this thing I need to do so I just need a little bit of help. Anyway, I have this clock counter on a few of my pages, counting down to 0 and what I need to do is execute certain code 15 minutes before a counter reaches 0. It's basically the same code but it needs to run every time one of the counters is 15 minutes away from 0. Any simple way for me to achieve this? Thanks! I was under the impression this was a simple thing to do and I'm fairly certain I've done it before, but it isn't working for some reason. Under the root directory of my project I have two subfolders called "inc" and "lib". lib contains third-party scripts for use in my project. The one in question is phpmailer (lib/class.phpmailer.php). Now, in inc I have a file that needs to include PHPMailer. Inside my script in inc I have this: require_once('../lib/class.phpmailer.php'); It errors out saying it can't find it. I thought that was supposed to go down one directory then back up into lib. The file does indeed exist. What am I doing wrong? This seems like a stupidly simple thing... 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 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) I'm really sorry if this has been answered (I assume it has) I'm unfamiliar with search terms of what I am trying to do. I have this web page Code: [Select] <html> <body> <?php $con = mysql_connect("localhost","user","pass"); if (!$con) { echo "Fail"; die('Could not connect: ' . mysql_error()); } echo "Triumph"; ?> </body> </html> Which I got from a snippet. I load the webpage expecting to see fail or triumph, but I see nothing. My question is how to run the php script so I see something on the page (hopefully triumph. I apoligise for my noobness, I'm a PHP know nothing at the moment. 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. What this parameter 'absolute' in DateTime::diff does? I have done some tests but i cant percept what is different when i set this parameter 'true'. Can you explain to me?! Thanks a lot. Best regards. 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" ? How does one get the absolute filepath of this:
$_FILES["myfile"]["name"]
On a web-server?
Currently I'm feeding my image as a resource into imagejpg.
http://php.net/manua...n.imagejpeg.php
However, I need to get the file-path so I can send them to an S3 bucket.
Thanks for any help!
Edited by arbitrageur, 02 November 2014 - 09:35 PM. |