PHP - Folder Path Without The /var/www/html/ Php
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? Similar TutorialsI 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, 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? When having different levels of directories, using relative paths will not work anymore, for example: controller - authentication File 1: include('../../model/header.php') model File 2: header.php view File 3. style.css The header.php file includes the css file with a relative path, but the problem is it includes it as follows: ../view/style.css When now the header.php file gets included into File 1 in the folder "authentication", then the css file will not be accessible anymore, for it to be accessible you would have to go two directories up. In this sense my question is, what would be the proper path structure for a folder structure with multiple levels? Should I rather use absolute paths, I am not so prone of absolute path. What if the folders changes a bit, or the domain changes, or the location changes? Hi
I echo out images from a folder. The problem is that I have a html file in the same folder but I don't want to echo that out. How can I write my code to get rid of the html in the output?
Here my code:
<?php $filetype = '*.html'; $dirname = substr('$filetype'); $i=0; if (isset($_POST['submit2'])) { //get the dir from POST $selected_dir = $_POST['myDirs']; //now get the files from within the selected dir and echo them to the screen foreach(glob($selected_dir . DIRECTORY_SEPARATOR . '*') as $dirname) { echo substr($dirname, 0, -4); echo '<img src="'.$dirname.'" />'; echo "<label><div class=\"radiobt\"><input type='radio' name='radio1' value='$i'/></div></label>"; } } ?>P.S. when I echo out : substr($dirname, 0, -4); I want to get ride of the html filename there too. How can I do so something like this? Hi All
I have directory fiole like this
my_website/flash/file.html
I want to disable redirect to file.html via URL.
I have create .htpasswd and create .htaccess in flash folder with this code
# the auth block
AuthName "Please login."
AuthGroupFile /dev/null
AuthType Basic
AuthUserFile C:/xampp/htdocs/.htpasswd
# Here is where we allow/deny
Order Deny,Allow
Satisfy any
Deny from all
Require valid-user
Allow from env=noauth
Satisfy any
its Work, people cant redirect via change the URL but it also occurs with valid user via Login Session.
How to Set .htaccess file for bypass the .htpasswd via login Session user ?
How to solve it?
thanks
I got this script: But it give me error, file_get_contents cannot open stream. I need to add the FTP connection with user/pass paramaters. then look in set http url, to get the file contents(images) and transfer to ftp server location. Can Anyone take alook and tell me if I am going down the right path and how to get there. Please Code: [Select] function postToHost($host, $port, $path, $postdata = array(), $filedata = array()) { $data = ""; $boundary = "---------------------".substr(md5(rand(0,32000)),0,10); $fp = fsockopen($host, $port); fputs($fp, "POST $path HTTP/1.0\n"); fputs($fp, "Host: $host\n"); fputs($fp, "Content-type: multipart/form-data; boundary=".$boundary."\n"); // Ab dieser Stelle sammeln wir erstmal alle Daten in einem String // Sammeln der POST Daten foreach($postdata as $key => $val){ $data .= "--$boundary\n"; $data .= "Content-Disposition: form-data; name=\"".$key."\"\n\n".$val."\n"; } // Sammeln der FILE Daten if($filedata) { $data .= "--$boundary\n"; $data .= "Content-Disposition: form-data; name=\"".$filedata['name']."\"; filename=\"".$filedata['name']."\"\n"; $data .= "Content-Type: ".$filedata['type']."\n"; $data .= "Content-Transfer-Encoding: binary\n\n"; $data .= $filedata['data']."\n"; $data .= "--$boundary--\n"; } // Senden aller Informationen fputs($fp, "Content-length: ".strlen($data)."\n\n"); fputs($fp, $data); // Auslesen der Antwort while(!feof($fp)) { $res .= fread($fp, 1); } fclose($fp); return $res; } $postdata = array('var1'=>'today', 'var2'=>'yesterday'); $filedata = array( 'type' => 'image/png', 'data' => file_get_contents('http://xxx/tdr-images/images/mapping/dynamic/deals/spot_map') ); echo '<pre>'.postToHost ("localhost", 80, "/test3.php", $postdata, $filedata).'</pre>'; I want to copy everything in templates/blue to the folder code/ However: shell_exec("cp -r 'templates/blue' 'code'"); Creates a folder called blue inside code. I tried cp -r 'templates/blue/*' 'code', but that didn't do anything. Any ideas? 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 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. 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 Hello, I would like to know how to include a root file in a 4 deep folder using dots. Is it good : include "../../../config.php" or i can simple include "./config.php" ? How does this works? Is it better to write all the path? Thank you 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 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']} "; } Hi,
I am trying to setup cakephp cake console in win7 and run cake bake as in the link below.I set up the env variable in win7 as below with a php and cakeapp entry in this Path.I have easyPHP 12.1 and php works fine. I get an error with php in failing to load. dynamic library but the php dir is in the path below so I have no idea .
I cant set my php env var is my problem . The php.ini is in this dir specified below.
http://www.nurelm.co...ols-in-windows/
E:\Program Files\EasyPHP-12.1\php\php546x121019214357\;E:\AA-website design\acl\app\Console\;
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 ?> Im having a strange path problem. The problem is that in the base directory, i have some php files. These goes well. I also have two folders: one for my function library, and other for some type of webpages. My problem is that if i changue to a webpage in that folder through the menu in the base directory the path itself it also changues, so it became that directory. Base dir: tr Library directory: lib Category dir: categorias (these two are in tr, and tr in www of wamp) If i echo a link like this in some page that is in the tr directory: <li><a href="categorias/listar_memoria_ram.php">List RAM Memory</a></li> And i go to that web, the include path changues, so it became categorias. I use functions to echo the menu each time, so, it dont work because it uses the relative path, so, if i echo this again: <li><a href="categorias/listar_memoria_ram.php">List RAM Memory</a></li> the url thas is finally called in the web explorer is: http://localhost/tr/categorias/categorias/listar_Memoria_Ram.php That dont exist. Note also that all my web functions are in a file that exists in the lib library and thats included each time using this: include_once '/../lib/lib_inventario.php'; That file have a impMenu function that is used each time, and all the others. What i was seeking if a plain way of controlling the path so it became more simplier and i could just use a single path, without exceptions. Or at least an explanation that why these happens. Ask for whatever any extra information you need. 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 |