PHP - File Directory Navigation Php Include
Hi,
I have a file structure for all my files on my website that works fine for the most part. The basic layout would be something similar to the following. - root folder - sub_folder1 - folder1 - folder2 -sub_folder2 - folder1 - folder2 Each of the folders would contain relative .php files carrying out specific functions etc. The issue I am having is as follows. If I am on a webpage that is located in either of the folder1/folder2 folders, and I need to redirect somebody to a file located in the root folder, I am not able to do this without the page not being displayed correctly. On the file located in the folder1 folder, I have a <? php include("page1.php");?> which works fine. Trying to access a file to redirect to from this folder, I have tried, <? php include("../page1.php");?>, but this only bring me up one level, <? php include("../../page1.php");?> which I think is wrong anyway, and doesn't work, and also <? php include("./page1.php");?>, again does not work. Does anyone know if it is possible to get the file from the subfolders to access a file located directly in the root? Sorry if I'm not being clear explaining the layout etc. Thanks. Similar TutorialsHello, I've got what should be a simple solution here. I've tried many things but it just won't work for me. This is what I have. I've got a wysiwyg editor setup to write to a file called news.php. The file that has the editor is edit/index.php. It's just a simple textarea. The textarea is supposed to include news.php. For some reason, it won't let me include that file that is in a lower directory. The file that writes to news.php is called edit/write.php. edit/write.php doesn't write to news.php instead it writes to edit/news.php. The only reason I want to include the lower directory is so that I can put a .htaccess password protection on the edit directory. I'll include some code below. Code: (edit/index.php) [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> <head> <title>Editing News</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <script type="text/javascript" src="nicEdit.js"></script> <script type="text/javascript"> bkLib.onDomLoaded(function() { nicEditors.allTextAreas() }); </script> <form method="post" action="write.php"> <p> <textarea name="content" style="width:100%;height:1000px;"><?php include '../news.php';?></textarea> <input type="submit" value="Save" /> </p> </form> </body> </html> Code: (edit/write.php) [Select] <?php $File = "../news.php"; $Handle = fopen($File, 'w'); $Data = $_POST['content']; fwrite($Handle, $Data); fclose($Handle); header("Location: index.php"); ?> index.php is just a simple include news.php. Am I missing an easy step? Any help would be great!! Thanks! Selected navigation on include file. Hi all I can't think how to do this or even if it's possible so I'm hoping someone can help. I have a simple example here to illustrate. http://www.ttmt.org.uk/three.php It's just four linked pages with a heading and a navigation. The navigation has an id="selected" in the <a> tag for that page that changes the color of that link to show you are on that page - very basic. I wanted the put the navigation on the pages with an include file. Code: [Select] <?php include("php/includes/nav.php"); ?> and have the code for the nav in nav.php nav.php Code: [Select] <ul id="nav"> <li><a href="index.php">Home</a></li> <li><a href="one.php">One</a></li> <li><a href="two.php">Two</a></li> <li><a href="three.php">Three</a></li> </ul> My problem is how can I add the id="selected" to the different links for the different pages if I'm including the navigation code? Hope this makes sense and someone can help. Any help would be greatly appreciated. Hey all, I viewed this tutorial and the guy used $_SERVER['DOCUMENT_ROOT'] to reference a view layout for his specific index file. So I tried to imitate and did exactly what he did, but for me I got the following error: Code: [Select] Warning: include(/Users/jmerlino/Sites/mark/public/diet/views/layouts/shop.php) [function.include]: failed to open stream: No such file or directory in /Users/jmerlino/Sites/diet/index.php on line 22 Warning: include() [function.include]: Failed opening '/Users/jmerlino/Sites/mark/public/diet/views/layouts/shop.php' for inclusion (include_path='.:/usr/lib/php') in /Users/jmerlino/Sites/diet/index.php on line 22 This is the php code that is causing this error: include($_SERVER['DOCUMENT_ROOT'].'/'.'diet/views/layouts/'.$controller.'.php'); I'm not sure why it's going to: /Users/jmerlino/Sites/mark/public/diet/views/layouts/shop.php instead of: /Users/jmerlino/Sites/diet/views/layouts/shop.php Thanks for any response I am trying to include a inc.php file within a normal .php file from a single directory as I am using it in several directories but cannot get it to work and have tried many different techniques. Any ideas on the coding that would work would be appreciated? Alternatively, I would be happy to set the constants in a mysql db but am unsure how I would unpack/read it so as to get it in the php program as code i.e. mysql db field 1 field 2 name $name Program <?php $name; ?> is there a way to do an include or require to a whole directory? I have only done includes and requires with single files in the past, but have a situation where this could save me a lot of time. I am trying to use the following code to include a directories contents and was wondering what im doing wrong, because its not working? Code: [Select] if ($handle = opendir('../configs')) { while (false !== ($FILEZ = readdir($handle))) { include "$FILEZ"; } closedir($handle); } How do you include files from a higher up directory? I'm currently working on a file in public_html/Directory/otherdirectory and want to include a config file that's in public_html/Directory so how would I include public_html/Directory/config.php in the public_html_Directory/otherdirectory/index.php file? I've tried using ../ and ../Directory/ in the includes line but got errors both times Edited April 11, 2020 by Nematode128I havent included the whole title as it wouldnt let me but I was wondering if someone could help me on this? I know this is possible as torrentflux caters for this but unsure of where to start. I dont want to allow file or directory uploads or creation in my /etc/php.ini file (this is turned off). Yet then torrentflux allows me to link a torrent from an external source (using legal downloads of course ) but then it uploads it on my server and creates folders on a per user basis. How is this possible can someone give me some pointers please? I look forward to any replies, Jeremy. I have a php file that generates a string that I need to use in a .js (javascript)file. Being that php developers sometimes using javascript with php, Im hoping someone can help me with this, cause i dont know any javascript. Code: [Select] //This is the varible inside the .js file var suggestionText = "I need to be able to include my string generated by the php file here..."; I'm in the middle of making my own CMS system, where a user can create a page online via a text editor, I know how to create and save the file, but to make the process easier I would like to a function where a user can click a button find a list of files and folders, pick the folder location to save a new file to. Instead of having to type something like this /commonPages/aboutUs/ with the file name being test.php What would be the easiest way to do this? I have just been looking at opendir() and my first thought was to use <input type="file" />, but then I remember that was only for inputting a particular file name, which would be useful for renaming a file at a later date. For example, if we wanted to change test.php to something more meaningful ie history.php Why does this code: Code: [Select] require_once "../../media/php/classes/Mysql.inc.php"; Work when I go to: http://mysite.com/API/v1/index.php But when I go to: http://mysite.com/index.php it doesn't work. The require is being called from another class, which I call from the two pages above. The class loads, but in the second link, I get failed to open stream: No such file or directory but the first one works fine. What would cause this? could this be an htaccess thing? htaccess: Code: [Select] Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.+)$ /$1.php [L,QSA] In my script, I'm trying to create a file with the name of a variable in a different directory. My code is: Code: [Select] $handle = fopen("cheese/" . $page . ".html", "w");Output: Warning: fopen(cheese/test.html) [function.fopen]: failed to open stream: No such file or directory in /home/a5938041/public_html/newfile/newpage.php on line 6 What's happening here? (sorry I'm a total noob.) After a user on my site deletes their account I want their profile picture to be deleted from my images folder. I was testing the unlink function on my index.php file and it is failing. Here is the error: Warning: unlink(/assets/img/avatars/users/jasongordon.png): No such file or directory in /home/www-data/big.com/index.php on line 86 My code was just: unlink('/assets/img/avatars/users/jasongordon.png'); I'm not sure why this fails because my file does exist. Hi,
I have this code
<?php // Must include this include("geoiploc.php"); function getYJLINKS($default_font_family,$yj_copyrightear,$yj_templatename,$show_tools,$show_fres,$show_rtlc,$validators_off,$totop_off){ $allLinks = array(); if((function_exists('toolbox_urls') && $show_tools == 1) || $validators_off == 1 || $totop_off == 1){ echo '<div class="validators">'; if($validators_off == 1){ $allLinks[] ='<a href="http://jigsaw.w3.org/css-validator/check/referer?profile=css3" target="_blank" title="CSS Validity">CSS Valid</a>'; $allLinks[] ='<a href="http://validator.w3.org/check/referer" target="_blank" title="XHTML Validity">XHTML Valid</a>'; } if($totop_off == 1){ $allLinks[] ='<a class="yjscroll" href="#stylef'.$default_font_family.'">Top</a>'; } if (function_exists('toolbox_urls') && $show_tools == 1): global $font_size; global $font_direction; if ($show_fres == 1): $allLinks[] = '<a id="fontSizePlus" class="fs" href="javascript:;" rel="nofollow">+</a>'; $allLinks[] = '<a id="fontSizeMinus" class="fs" href="javascript:;" rel="nofollow">-</a>'; $allLinks[] = '<a id="fontSizeReset" class="fs" href="javascript:;" rel="nofollow">reset</a>'; endif; if ($show_rtlc == 1): $allLinks[] = '<a class="tdir" href="'.$font_direction[1].'" rel="nofollow">RTL</a>'; $allLinks[] = '<a class="tdir" href="'.$font_direction[2].'" rel="nofollow">LTR</a>'; endif; endif; echo implode(' | ',$allLinks); echo '</div>'; } // loading this from a database $ip = $_SERVER["REMOTE_ADDR"]; // listing Country Flags Images $dir = 'images/flags'; $file_display = array('png'); if (file_exists ($dir) == false) { echo 'Directory \'', $dir, '\' not found!'; } else{ $dir_contents = scandir($dir); foreach($dir_contents as $file) { $file_type = strtolower(end(explode('.', $file))); If($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true) if($file == '..' || $file == '.') { continue; } $code = strtolower(getCountryFromIP($ip, "code")); echo '<div class="yjsgcp">Palana.it ® 1994 - '.$yj_copyrightear.' :: Tutti i diritti riservati :: Realizzazione Palana.it ││ Utente rilevato: IP: '. $ip . ', '.getCountryFromIP($ip, " NamE ").' ('.getCountryFromIP($ip, "code").'-'.getCountryFromIP($ip, "AbBr").') '; echo '<img src="', $dir, '/', $code, '.png" /> </div>'; } } } ?>The problem, as we see (http://www.palana.it), is that code printed the Italian flag but many times there are images in the directory, that is over 204. See bottom of the page. How can I fix the code to get ONE display? Hey, I dont know whats wrong but i was hoping someone could take a look at the code and provide some errors that maybe causing this script not to work. I want it to display all the .jpg pictures in thumbnails, it currently does not even get the pictures. code: <?php $pic_listing = mysql_query("SELECT * FROM toplist WHERE id='". $id ."'") or die(mysql_error()); while($serverpic = mysql_fetch_array($pic_listing)) { $servername = $serverpic["servername"]; } $directory = "images/serverpic/" . $servername . ""; $images = glob("" . $directory . "*.jpg"); if(empty($images)) { ?> <div class="highslide-gallery"> <?php foreach($images as $image) { ?> <a href="images/serverpic/<?php echo $servername . "/" . $image; ?>" class="highslide" onclick="return hs.expand(this)"> <img src="images/serverpic/<?php echo $servername . "/" . $image; ?>" alt="Highslide JS" width="100" height="100" title="Click to enlarge" /> </a> <div class="highslide-caption"> <?php } ?> </div> </div> <?php } ?> $file="../myclients/clients/".$company_name."/Download/".$file_name; $size = filesize($path); // not working i try with function also function formatbytes($file, $type) { switch($type){ case "KB": $filesize = filesize($file) * .0009765625; // bytes to KB break; case "MB": $filesize = (filesize($file) * .0009765625) * .0009765625; // bytes to MB break; case "GB": $filesize = ((filesize($file) * .0009765625) * .0009765625) * .0009765625; // bytes to GB break; } if($filesize <= 0){ return $filesize = 'unknown file size';} else{return round($filesize, 2).' '.$type;} } echo formatbytes($file, "KB"); uploaded file size is 488 kb but it showing "unknown file size" please help me. I have a file system browser i'm writing for a client. I would like to know if there's a way to determine if an object is a directory or file, so I can display a proper icon next to it depending on what it is. Any help is appreciated. file_get_contents() has suddenly stopped working for me. I keep getting this error: Code: [Select] Warning: file_get_contents(/Users/ttocskcaj/MineCMS/public/js/jquery.js ) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in /Users/ttocskcaj/MineCMS/controllers/m.controller.php on line 44 The file(s) definitely exist, I can use nano to open them, and permissions are 777 on all the files. The lampp error log has nothing. Not even a No such file or directory error as you'd expect. Any ideas what's going on? hey guys im tyring to read my directory (whole of the web server)...i want to be able to put the file name and root into an array...im just wanting to know whats the best function i need to do this please?...thank you www.desmond-otoole.co.uk/secure/securefunctions.php /bank/admin/index.php what should I do in the index.php file to access securefunctions.php
require("../secure/SecureFunctions.php"); Nothing seems to work
I just get a stupid google chrome page saying |