PHP - Simple Stylesheet Absolute Path
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! 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 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. 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" ? 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? I have a script.. it works fine on my localhost.. now i am trying to work it with on my remote server.. the script reads the folder in my c drive and shows me the file on display here is the code <?php $main_dir ="C:\\xampp\\htdocs\\xtrajam"; $main_open = opendir($main_dir); while(($main_file = readdir($main_open)) != FALSE) { echo $main_file."<br />"; } closedir($main_open); ?> Now the thing is this works fine on local host as it can easy access the path C:\\xampp\\htdocs\\xtrajam Now i want this path to be accessed sumhow wen i try it on my remote server.. how should i do that like when i run the script online it reads the contents from my c drive directory..? is it sumhow possible? Hello: I am trying to make a StyleSheet updateable from my admin panel, but I'm not sure if what I want to do is possible. So ... I have a TEXTAREA in my admin panel that writes to the DB just fine. it has styles like: Code: [Select] body { margin: 5px 0; padding: 0; background-color: #ebe9e6; background-image: url('../images/Site-BG2.jpg'); background-position: center bottom; background-repeat: no-repeat; background-attachment: scroll; font-family: arial, sans-serif; font-size: 100%; line-height: 1.4em; } ... Etc... On the frontend, it writes into the StyleSheet just fine like: Code: [Select] <?php include('myConn.php'); //contains your mysql connection and table selection $query=mysql_query("SELECT * FROM myStyleSheet") or die("Could not get data from db: ".mysql_error()); while($result=mysql_fetch_array($query)) { $myPageData=$result['myPageData']; } ?> <?php echo $myPageData; ?> So, what I want to see is if I can somehow pull the styles onto the page like: Code: [Select] <link rel="stylesheet" type="text/css" href="include/StyleSheet.css" /> Now, if I do it as listed above it and look at the code it displays the Code: [Select] <?php include('myConn.php'); //contains your mysql connection and table selection Etc... If I do it like Code: [Select] <link rel="stylesheet" type="text/css" href="include/StyleSheet.php" /> It displays the styles fine, but the browser doesn't read it as a StyleSheet and therefore the page doesn't get formatted. So, is there any way to make this work? Anyone have any ideas about this? The idea is so I can manage the Styles via an admin panel remotely without having to login with web editing software. Thanks. Hi, Can someone why my stylesheet is not working? Code: [Select] <?php header('Content-type: text/html; charset=utf-8'); include 'config.php'; include 'lib.php'; $db = dbConnect(); if (isset($_GET['ip'])) { $ip = $_GET['ip']; $longitude = $_GET['long']; $latitude = $_GET['lat']; $searches = getSearchesByIP($ip); $watchUser = true; } else { $searches = getSearches(); $watchUser = false; } dbClose($db); ?> <html> <head> <title>cms</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="inc/css/style.css" /> </head> <body> <h1>WTF</h1> <div id="container"> <? if ($watchUser == true) {?> <a href=searches.php> See all</a> <br/> <table> <tr> <th>ip</th> <td><?=$ip;?></td> </tr> <tr> <th>longitude</th> <td><?=$longitude;?></td> </tr> <tr> <th>latitude</th> <td><?=$latitude;?></td> </tr> </table> <? } ?> <br/> <table> <tr> <th>id</th> <? if ($watchUser == false) echo "<th>ip</th>"; ?> <th>question</th> <? if ($watchUser == false) echo "<th>longitude</th>"; ?> <? if ($watchUser == false) echo "<th>latitude</th>"; ?> </tr> <? foreach($searches as $search) { ?> <tr> <td><?=$search['id'];?></td> <? if ($watchUser == false) { echo "<td> <a href='searches.php?ip=" . $search['userIP'] . "&long=" . $search['longitude'] . "&lat=" . $search['latitude'] . "'>" . $search['userIP'] . "</ a> </td>"; } ?> <td><?=$search['question'];?></td> <? if ($watchUser == false) echo "<td>" . $search['longitude'] . "</td>"; ?> <? if ($watchUser == false) echo "<td>" . $search['latitude'] . "</td>"; ?> <td><a href="answers.php?id=<?=$search['id'];?>">see answers</a></td> <td><a href="inc/php/utils/search-delete.php?id=<?=$search['id'];?>">delete</a></td> </tr> <? } ?> </table> </div> <a href="search.php">Add new</a> </body> </html> my css file: a:link {color:#FF0000;} /* unvisited link */ a:visited {color:#00FF00;} /* visited link */ a:hover {color:#FF00FF;} /* mouse over link */ a:active {color:#0000FF;} /* selected link */ /* table { font-family: "Arial"; font-size: 10px; color:red; } */ table, th, td { border:1px solid black; } h1 {color:#00ff00;} Hi, I wanted to know how to link a stylesheet using php specifically for the purpose of loading a different stylesheet when the home page displays. I heard of echoing out the stylesheet but I do not know how. Any help would be appreciated. Okay the reason I'm doing it this way is because I work locally and then transfer them to the production site. For some reason, this isn't working even though when I view the page source, it has the right URL, but when it's clicked it goes to a blank page, but when I copy and paste, it goes to the right page. Anywho, this is what I'm trying: Code: [Select] <?php $homeURL = 'localhost:90/Elvonica'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Elvonica</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <link rel="stylesheet" type="text/css" href="<?php echo $homeURL; ?>/template/css/skySpirit.css" /> I didn't plug in the rest to ignore it since it's not part of the problem. It's printing: localhost:90/Elvonica/template/css/skySpirit.css, but when it's clicked, goes to blank page. When it is copied and pasted, it goes to the right page. I have a feeling you can't include PHP inside a link rel or any sort of that header information. If anyone could please help me how to do this, I would appreciate it. FYI: I did have just template/css/skySpirit.css and it worked until I go into a another directory like forums/index.php. Then it tries to go localhost:90/Elvonica/forums/template/css/skySpirit.css and it's not in there obviously. Thank you for anything that you can offer! I know how to do the includes with the dirname(__FILE__). ...in a different folder? For instance, I have a stylesheet in my C:\xampp\htdocs\rcm folder, and I want to link it to files in the C:\xampp\htdocs\ folder. Is there a way of doing this? Thanks in advance 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, 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 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 ?> 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, How can i show image using absolute path instead of virtual path?? Help please |