PHP - Path Problem
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. Similar TutorialsHi! 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? 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 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? Hi there, i follow a tutorial from www.phpwebcommerce.com and i'm having path problem for 'add to cart' button. Demo from phpwebcommerce: http://www.phpwebcommerce.com/plaincart/index.php I have modified some changes, i'm putting the 'add to cart' button to 1st level instead of 2nd level. Example, under all category (car & manga) i choose car, then inside car category list there is a 'add to cart' button under all car product instead of clicking inside and show 'add to cart' button. productDetail.php: Code: [Select] <?php if (!defined('WEB_ROOT')) { exit; } $product = getProductDetail($pdId, $catId); // we have $pd_name, $pd_price, $pd_description, $pd_image, $cart_url extract($product); ?> <table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td align="center"><img src="<?php echo $pd_image; ?>" border="0" alt="<?php echo $pd_name; ?>" width="230" height="170"></td> <td valign="middle"> <strong><?php echo $pd_name; ?></strong><br> Price : <?php echo displayAmount($pd_price); ?><br> <?php // if we still have this product in stock // show the 'Add to cart' button if ($pd_qty > 0) { ?> <input type="button" name="btnAddToCart" value="Add To Cart >" onClick="window.location.href='<?php echo $cart_url; ?>';" class="addToCartButton"> <?php } else { echo 'Out Of Stock'; } ?> </td> </tr> <tr align="left"> <td colspan="2"><?php echo $pd_description; ?></td> </tr> </table> I copy this code out from productDetail.php: Code: [Select] <input type="button" name="btnAddToCart" value="Add To Cart >" onClick="window.location.href='<?php echo $cart_url; ?>';"> productList.php: Code: [Select] <?php if (!defined('WEB_ROOT')) { exit; } $productsPerRow = 2; $productsPerPage = 8; //$productList = getProductList($catId); $children = array_merge(array($catId), getChildCategories(NULL, $catId)); $children = ' (' . implode(', ', $children) . ')'; $sql = "SELECT pd_id, pd_name, pd_price, pd_thumbnail, pd_qty, c.cat_id FROM tbl_product pd, tbl_category c WHERE pd.cat_id = c.cat_id AND pd.cat_id IN $children ORDER BY pd_name"; $result = dbQuery(getPagingQuery($sql, $productsPerPage)); $pagingLink = getPagingLink($sql, $productsPerPage, "c=$catId"); $numProduct = dbNumRows($result); // the product images are arranged in a table. to make sure // each image gets equal space set the cell width here $columnWidth = (int)(100 / $productsPerRow); ?> <table width="100%" border="0" cellspacing="0" cellpadding="20"> <?php if ($numProduct > 0 ) { $i = 0; while ($row = dbFetchAssoc($result)) { extract($row); if ($pd_thumbnail) { $pd_thumbnail = WEB_ROOT . 'images/product/' . $pd_thumbnail; } else { $pd_thumbnail = WEB_ROOT . 'images/no-image-small.png'; } if ($i % $productsPerRow == 0) { echo '<tr>'; } // format how we display the price $pd_price = displayAmount($pd_price); echo "<td width=\"$columnWidth%\" align=\"center\"><a href=\"" . $_SERVER['PHP_SELF'] . "?c=$catId&p=$pd_id" . "\"><img src=\"$pd_thumbnail\" border=\"0\" width=\"230\" height=\"170\"><br>$pd_name</a><br>Price : $pd_price<br> <input type=\"button\" name=\"btnAddToCart\" value=\"Add To Cart >\" onClick=\"window.location.href='<?php echo $cart_url; ?>';\" >"; // if the product is no longer in stock, tell the customer if ($pd_qty <= 0) { echo "<br>Out Of Stock"; } echo "</td>\r\n"; if ($i % $productsPerRow == $productsPerRow - 1) { echo '</tr>'; } $i += 1; } if ($i % $productsPerRow > 0) { echo '<td colspan="' . ($productsPerRow - ($i % $productsPerRow)) . '"> </td>'; } } else { ?> <tr><td width="100%" align="center" valign="center">No products in this category</td></tr> <?php } ?> </table> <p align="center"><?php echo $pagingLink; ?></p> The code i copy from productDetail.php i paste in productList.php at line48, it show the 'add to cart' button but when i click on it, it cant add to my shopping cart and it show error: Notice: Undefined variable: cart_url in C:\Domains\xxxxxxxx\wwwroot\xxxxxxxx\plaincart\include\productList.php on line 48 Notice: Undefined variable: cart_url in C:\Domains\xxxxxxxx\wwwroot\xxxxxxxx\plaincart\include\productList.php on line 48 Notice: Undefined variable: cart_url in C:\Domains\xxxxxxxx\wwwroot\xxxxxxxx\plaincart\include\productList.php on line 48 Notice: Undefined variable: cart_url in C:\Domains\xxxxxxxx\wwwroot\xxxxxxxx\plaincart\include\productList.php on line 48 Will Appreciate For Any Help....Thank you in advanced & sorry for the bad English. Hello. My question for majority is very simple but not for me...
I would like to change photo for other at the top on the subpage in this link http://www.grimlord.eu/index_pl.php?src=gallery&sub=koncertowe Here is good http://www.grimlord.eu/index_pl.php?src=galeria What I can do? I used index.pl.php file
So, I am your typical newbie to php. I am usually doing more design stuff, but now I am diving into PHP. The script in question is made for a user to upload an image to a respective directory. Also the path, category, and 2 tags representing the image will be uploaded to a mySQL database. My problem is that I have pieced together some freeware scripts that I have found in order to accomplish my ultimate goal. I need the form to be processed on the same page, because I don't want to redirect users. I also need to upload the respective information to the database. Right now, when you upload an image it only seems to be processing a part of the form, and does not upload any of the information at all. Can someone spot the many things that I am doing wrong and provide me with some direction? I have two files in question image_upload.php (Sorry about all of the code) <?php require_once 'upload_config.php'; function VerifyForm(&$values, &$errors) { // Do all necessary form verification if($clear_folder_before_upload){ $mydirectory = myUploadDir(); EmptyDir($mydirectory); } $uploaded_file_counter=0; $UploadLimit = $_POST['counter']; for($i=0;$i<=$UploadLimit;$i++){ $file_tag='filename'.$i; $filename=$_FILES[$file_tag]['name']; if($filename!=null) { $rand=time(); $str="$rand$filename"; // set folder name in here. $filedir= myUploadDir(); //change the string format. $string= $filedir.$str; $patterns[0] = "/ /"; $patterns[1] = "/ /"; $patterns[1] = "/ /"; $replacements[1] = "_"; $dirname=strtolower(preg_replace($patterns, $replacements, $string)); //end of changing string format //checking the permitted file types if($check_file_extentions) { $allowedExtensions = allowedfiles(); foreach ($_FILES as $file) { if ($file['tmp_name'] > '') { if (!in_array(end(explode(".", strtolower($file['name']))), $allowedExtensions)) { $fileUploadPermission=0; } else { $fileUploadPermission=1; } } } } else{ $fileUploadPermission=1; } //end of checking the permitted file types if($fileUploadPermission){ if(move_uploaded_file($_FILES[$file_tag]['tmp_name'],$dirname)) { echo "<img src='$dirname'>"; $uploaded_file_counter+=1; } } } } if($uploaded_file_counter==0){ echo "<br /> <b style='font-weight:bold;color:red'>Oops! Please select an image file</b>"; }else{ echo "<br /> <b>You requested ".$i." image files to upload and ".$uploaded_file_counter." files uploaded sucessfully</b>"; echo $filename0; $contentdiv = 'Upload succesful! Upload Again'; } } function DisplayForm($values, $errors) { ?> <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>JayGilford.com :: Name form example</title> <script type="text/javascript" src="js/jquery-1.4.2.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.custom.min.js"></script> <style type="text/css"> div#upload_box_wrapper{width:350px;text-align:center; float: left;font-family: verdana; font-size: 12px;padding: 5px 5px 5px 5px; color: black;} div#upload_box_wrapper #upload_title_text{text-align:left;width: 100%;display: block;border: 0px solid green; margin-bottom: 5px;} div#upload_box_wrapper #FileUploadDiv{display: block;width: 98%;border: 0px solid green; text-align: left;padding: 0px 0px 0px 0px;} div#upload_box_wrapper p.add-new-upload-box{float: left;width: 100%;text-align: left;} div#upload_box_wrapper a.add-new-upload-link{font-weight: bold;font-size: 13px;padding-right: 3px;text-decoration: none; color: black;} div#upload_box_wrapper .upload-button{border: 0px solid lightgreen;height:30px; width:120px;cursor: pointer;background:url(./images/upload_button.png) no-repeat center left; color: white;} </style> </head> <body> <form method='post' action='' enctype='multipart/form-data'> <div id="upload_box_wrapper"> <div id="upload_title_text">Image Upload:</div> <div id="FileUploadDiv" DivValue="0"> <input name='filename0' type='file' id='filename'> <select name="img_category"> <option value="Vacation">Vacation</option> <option value="Holiday">Holiday</option> </select> <input name="tag1" type="text" id="tag1"> <input name="tag2" type="text" id="tag2"> </div> <input type="hidden" value="0" id="counter" name="counter"> <div align='left'> <input type='submit' name='submit' value='Upload Now!' class="upload-button"> </div> </div> </form> </body> </html> <?php } function ProcessForm($values) { $filename0 = $_POST['filename']; $filetype = $_POST['']; $img_category = $_POST['img_category']; $tag1 = $_POST['tag1']; $tag2 = $_POST['tag2']; //////// //figure out the image?? ///// session_start(); $img = $_POST[ 'imglink' ]; $filetypes = array( 'gif','jpg','jpeg','png' ); ++$filetypes; $filetype = strstr( $img, '.' ); if( $filetype != $filetypes ) { echo 'not supported'; } session_register( 'Image' ); $Img = $_SESSION[ 'Image' ]; mysql_query( "INSERT into `images` ( `image_id`, `filename`, `filetype`, `url`, `img_category`, `tag1`, `tag2` ) VALUES ( '', '$filename0', '$filetype', '$Img', '$img_category', '$tag1', '$tag2' )" ); session_destroy(); mysql_close( $DB ); // Replace with actual page or redirect :P } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $formValues = $_POST; $formErrors = array(); if (!VerifyForm($formValues, $formErrors)) DisplayForm($formValues, $formErrors); else ProcessForm($formValues); } else DisplayForm(null, null); ?> and the upload_config.php file <?php /////////////////////////////////////////////////////////////////////////// //establish mysql connection (I have this set correctly on the original file) /////////////////////////////////////////////////////////////////////////// $db = mysql_connect('RESPECTIVE', 'MYSQL', IDANDPW'); if (!$db) { echo "Unable to establish connection to database server"; exit; } if (!mysql_select_db('chad_images', $db)) { echo "Unable to connect to database"; exit; } /////////////////////////////////////////////////////////////////////////// // set your upload directory name in here. /////////////////////////////////////////////////////////////////////////// function myUploadDir(){ $myUploadDir = "./upload/"; return $myUploadDir; } /////////////////////////////////////////////////////////////////////////// // if you want to imposs file type rescriction then // $check_file_extentions=1 or if you want to off this option then // $check_file_extentions=0 /////////////////////////////////////////////////////////////////////////// $check_file_extentions = 1; //////////////////////////////////////////////////////////////////////////// // set your allowed type in the array. // examples: zip, pdf, psd and many more. // //////////////////////////////////////////////////////////////////////////// function allowedfiles() { $allowed_file_extensions=array("png","jpg","gif","bmp"); return $allowed_file_extensions; } /////////////////////////////////////////////////////////////////////////// // if you want to delete all the files in uploaded directory // $clear_folder_before_upload = 1 or if you want to off this option then // $clear_folder_before_upload = 0 /////////////////////////////////////////////////////////////////////////// $clear_folder_before_upload = 1; function EmptyDir($dir) { $handle=opendir($dir); while (($file = readdir($handle))!==false) { @unlink($dir.'/'.$file); } closedir($handle); } ?> Any help would be greatly appreciated! 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, 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. 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 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. 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\;
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 ?> 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 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! I am trying to find the URL to a directory TWO levels above the script level (if you know what I mean). For example.. the script sits at Code: [Select] http://www.domain.com/TestArea2/members/index.php BUT I need to find the path to Code: [Select] http://www.domain.com/TestArea2/ the nearest I get is... $domain = $_SERVER['HTTP_HOST']; $domain .= $_SERVER['REQUEST_URI']; echo $domain; // outputs www.domain.com/TestArea2/members/index.php Is there a simple method to do this or have I got to split the string and work backwards? Many thanks 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, 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 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 Hi, How can i show image using absolute path instead of virtual path?? Help please 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']} "; } |