Jump to content

UrbanDweller

Members
  • Posts

    123
  • Joined

  • Last visited

Everything posted by UrbanDweller

  1. Bugging and testing finally found a way to work the return function needed to me edited
  2. Thanks man that did it, but now the below script doesnt work, the variable i create with the url inside doesnt pass into the previous code correctly. Is it due the variable starting with a forward slash? if(move_uploaded_file($_FILES['catImage']['tmp_name'], $imgDestination)){ return($imgDestination); }
  3. Thanks I understand the defining path stuff enough to get it working and inserting the absolute path into sql database, but like i said when i call it from the database and put it inside the html img src tag it adds the current web path to the image url from the database creating a useless url. It seems that everything requires a relative path in html/php cause once i put that url inside <img src"url" /> it seems to start looking from its current location not from where i ask in srv_root. I really cant imagine why this is so hard to define between a bloody relative and absolute path without adding its own path. Is this HTML or PHP issue, do i have to enable absolute pathing. IM CRAZY ATM!!
  4. Ok, well i got it to work all fine from both full comp path and web path but when I try open the image via the database url the src="c:/wamp/www/website/images/shop/img_cat/image.jpg" if i try open the image url directly i get current path and image path conjoining This has happened in the past but didnt think to check the link directly. How to stop this happening?
  5. Thanks for that I now finally understand what this code i was using as a reference means $thisFile = str_replace('\', '/', __FILE__); $docRoot = $_SERVER['DOCUMENT_ROOT']; $webRoot = str_replace(array($docRoot, 'library/config.php'), '', $thisFile); $srvRoot = str_replace('library/config.php', '', $thisFile); define('WEB_ROOT', $webRoot); define('SRV_ROOT', $srvRoot); That die() command will come in handy didnt really know how to use it cept for sql examples :S I just tried the die it returned "website/images/shop/img_cat/image.jpg" yet the rest of the script doesnt work until i create a local variable with the same path :S whats wrong
  6. I tried that before, I had it defined in a config file included in all the nessacary pages but it didnt seem to pass very well when i tried to join $_SERVER["DOCUMENT_ROOT"] with a image location variable but didn't work. Could you give me an example of root_document and if you can join a defined and a variable cause watever I tried doesnt work define("SRV_ROOT", $_SERVER["DOCUMENT_ROOT"]) $imgDir = SRV_ROOT . "images/shop/img_cat"; // THIS FAILS
  7. Hey, Im wondering how I go about creating a directory path to an image folder that can be opened from any folder inside my root web directory www/WEBROOT/IMAGES/SHOP/image.jpg When i add an absolute path to the images url in the database when its gets executed it will run the the path from the current folder. I was wondering how to make its always start looking for files from the root directory down instead of the current location. The reason im asking this is that i was to be able to open those images from seperate locations inside my website. Thanks
  8. Cool script to bad i dont know jquery. sure its not hard without it though
  9. na thats all fine i wrote down the .php files wrong add_category is the form and process_category processes the form Sorry bout that, the e
  10. this does talk to database.php <body> <?php require_once("../include/database.php")?> <form id="addCategoryForm" method="POST" action="process_category.php" enctype="multipart/form-data"> <input type="text" id="catName" name="catName" value=""/> <span>Will its display products?</span><input type="checkbox" id="isProduct" name="isProduct" /> <select name="parentCat"> <option name="noParent" value="0">Shop Homepage</option> <?php /* Script below fills select options with avaliable parent categories * from catagory_tbl database using a simple loop. */ $result = mysql_query( "SELECT cat_id, cat_name FROM catagory_tbl WHERE cat_isProduct=0 ORDER BY cat_id" ) or die("Query Failed:" .mysql_error());; // Loop starts if(dbNumRows($result) > 0){ while($row = dbFetchAssoc($result)){ extract($row); echo "<option value='".$cat_id."'>".$cat_name."</option>"; } } // Loop stops ?> </select> <input type="text" id="catDescription" name="catDescription" value=""/> <input type="file" id="catImage" name="catImage" /> <input type="submit" id="catSubmit" name="catSubmit" value="Submit"/> <input type="submit" id="catCancel" name="catCancel" value="Cancel"/> </form> </body> You have now got all my code lol
  11. catagory.php is called from the form i get the image etc from database.php & config.php are only related to catagory.php
  12. Here you go, thanks for having a look! config.php // Server root path $srvRoot = $_SERVER['DOCUMENT_ROOT']; //$serverRoot = str_replace('/', '\/', $serverRoot); define('SRV_ROOT', $srvRoot); //define('SRV_ROOT', $srvRoot); // Image directory path define('CATEGORY_IMAGE_PATH', 'lisahumphrey/images/shop/cat_img/'); define('CATEGORY_THUMB_PATH', 'images/shop/cat_thumb/'); database.php $sqlCon = mysql_connect($dbHost, $dbUser, $dbPass) or die ('MYSQL connection Failed. ' . mysql_error()); mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error()); // Database query functions function dbQuery($sql) { return mysql_query($sql) or die('Query failed. ' . mysql_error()); } addCategory.php require_once('../include/database.php'); require_once('../../library/config.php'); function addCategory(){ if(!isset($_POST["catName"], $_POST["catDescription"], $_FILES["catImage"])){ header('Location: category_add.php'); } $name = $_POST["catName"]; $description = $_POST["catDescription"]; $image = $_FILES["catImage"]["name"]; $image = addImage($image, SRV_ROOT); // FIX FIX FIX $parentId = $_POST["parentCat"]; if(isset($_POST["isProduct"])){ $isProduct = 1; }else{ $isProduct = 0; } $sql = "INSERT INTO catagory_tbl (cat_parent_id, cat_isProduct, cat_name, cat_description, cat_thumbnail) VALUES ($parentId, $isProduct, '$name', '$description', '$image')"; $result = dbQuery($sql); header('Location: category_list.php'); } function addImage($image, $path){ // FIX FIX FIX $fileExtension = getExtension($image); $image = substr(md5(rand() * time()), 0, 10).".".$fileExtension; $imgDestination = $path.$image; if($_FILES['catImage']['type'] != "image/gif" && $_FILES['catImage']['type'] != "image/jpg" && $_FILES['catImage']['type'] != "image/jpeg" && $_FILES['catImage']['type'] !="image/png" ){ echo "You may only upload image files"; }else{ //Moves the uploaded file to destination folder via the variable which includes image filename if(move_uploaded_file($_FILES["catImage"]["tmp_name"],$imgDestination)){ //MOVES IMAGE TO IMAGE DIR return($imgDestination); }else{ header("Location: ../../home.php"); } echo $imgDestination; } } function getExtension($fileName){ /* Gets image extension type from image name * Splits image name at the . to get name and extension. */ $fileNameParts = explode(".", $fileName); // Retrieves image extension. $fileExtension = end($fileNameParts); // Converts extension string into all lowercase $fileExtension = strtolower( $fileExtension ); // Returns fileExtension to previous code that called function getExtension return($fileExtension); }
  13. Oh ignore the $serverRoot str_replace it came with a snippet, just used to switch / with \, its doesnt get used in the script. and $path = SRV_ROOT . "images/shop/cat_img" The idea is to set the image path created from $path + $imageName to a sql table where i can use it to display the image later on from any page on my site due to the path being absolute.
  14. Hey, I'm in the process of making a site that involves multiple layers of folders. I have a form that uploads an image which i then try to move to the image folder using a define function using the document root + image folder but the image never gets saved to the defined location and the location isnt inserted into the sql query. Its a simple thing I want to do but since Im making a bigger site I want to maximize includes to reduce duplicate code. Include File - defines the document root srvRoot = $_SERVER['DOCUMENT_ROOT']; $serverRoot = str_replace('/', '\/', $serverRoot); define('SRV_ROOT', $srvRoot); Image Upload $image = $_FILES["catImage"]["name"]; $image = addImage($image, SRV_ROOT . "images/shop/img_cat"); function addImage($image, $path){ // FIX FIX FIX $fileExtension = getExtension($image); //this function works fine have tested in previous scripts so not needed $image = substr(md5(rand() * time()), 0, 10).".".$fileExtension; $imgDestination = $path.$image; if($_FILES['catImage']['type'] != "image/gif" && $_FILES['catImage']['type'] != "image/jpg" && $_FILES['catImage']['type'] != "image/jpeg" && $_FILES['catImage']['type'] !="image/png" ){ echo "You may only upload image files"; }else{ //Moves the uploaded file to destination folder via the variable which includes image filename if(move_uploaded_file($_FILES["catImage"]["tmp_name"],$imgDestination)){ return($imgDestination); }else{ header("Location: ../../home.php"); } echo $imgDestination; } }
  15. But why is it that if i call the query not from the include but inside the main file the same code works.
  16. Hey, I found some code online that references a bunch of sql commands in there own functions that can be called from a require_once(), All the ones I have tried work expect mysql_query when its called it returns this error: But once i paste the mysql_query into the main script it works fines. code below is mine and the online script. Webcode: $sql = "SELECT cat_id, cat_parent_id, cat_name, cat_description, cat_image FROM tbl_category WHERE cat_parent_id = $catId ORDER BY cat_name"; /* Don't know what getPagingQuery does and couldnt find any reference to it so i removed it and replaced with simple query in my own code */ $result = dbQuery(getPagingQuery($sql, $rowsPerPage)); My Code: $sql = "SELECT cat_id, cat_parent_id, cat_name, cat_description, cat_image FROM tbl_category WHERE cat_parent_id = $catId ORDER BY cat_name"; $result = dbQuery($sql); Include file: $dbHost = "localhost"; //SQL Server $dbUser = "root"; // Database username $dbPass = ""; // Database password $dbName = "lh_shop"; // Database name $sqlCon = mysql_connect($dbHost, $dbUser, $dbPass) or die ('MYSQL connection Failed. ' . mysql_error()); mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error()); // Database query functions function dbQuery($sql) { return mysql_query($sql) or die('Query failed. ' . mysql_error()); } Thanks, I really hope someone has had this issue
  17. Hey, My question is, is it possible to create an if statement for div.onmousedown that will then excute document.onmousemove call function. var div = document.getElementById('div'); document.onmousedown = eventHandler(); function eventHandler(){ if(div.onmousedown){ document.onmousemove = moveFunction(); } } The reason I ask this is that i have a script that moves a div in a certain area and need the div to move even if the mouse is not inside it. This mouse down function is not the only one so i need something that can work with multiple mouse functions depending on wat one wat clicked etc
  18. I dont think javascript allows you to move the users cursor, but I may be wrong. But functions like that can really be abused
  19. Thanks for that, imma put it the other way and see how it goes. That script was just an example of what i want my code to do, I just dont like posting massive amounts of code wen i only need to understand a portion of whats going on. Cause before that return statement returns the function to the function that called that etc but not needed in example imo.
  20. Oh well im assuming wen i return true or false it get put inside the limited variable but it deoesnt seem to stop the script if its true.
  21. Hey again Im wanting to call a function inside a function that will check some variables to see if they are in range and return true or false depending on if they are in or out of the required range. Once returned to previous function check the to return for true or false to see whether script should continue. Code layout that i am currently trying, I use global variable in the script but for example i will use local ones. function foo(){ var testMe = 3 var limited = checkLimit(testMe); if(limited == true){ return; } //code continues if limited == false } function checkLimit(e){ if(e == 3){ return true; } // If doesnt equal 3 return false; Thanks guys, I truly love this place makes learning coding enjoyable, if you hit a brick wall you can always come here for advice!!
  22. Hey thanks for that I tried it but due to me have a div inside div inside a div making they all fit inside is becoming hard. My current css looks like so.. //Div 1 Parent Div #imgDiv { position: relative; background-color: #999; background: #CCC; z-index: 0; } // Div 2 child of Div 1 #cropDiv { position: absolute; top: -1px; left: -1px; border: solid 1px #000; z-index: 1; } // Div 3 child of Div 2 #moveDiv{ position: absolute; height: 10px; width: 10px; border-left: solid 1px #000; border-top: solid 1px #000; }
  23. Hey, all I can say is, input[type="button"]{ width: 50px; } NOT input[type=button]{ width: 50px; }
  24. Hey, I have a parent div where i would like to place a child div inside it, positioned in the bottom right corner. The child div will be a button that make the parent div change size so I was wondering the simplest way to always position the child div in the bottom right corner no matter what the size is. I am using js to modify the css and will used to change the size of the parent div. Current method ideas: float: right; top: 200px; top: 200px; left: 200px; I have a function that can get the top left positioning but less code the better so if there's a simpler way with float etc Im all ears!
  25. Thanks to you nogray and you answer I have got the mouseup to work and have now been able to make some real improvements on my code to fit a more dynamic approach. The movement is working perfectly i can mousedown and move the div every time and remove it from the last position i left it, now I have to figure out a way to limit the div movement inside the div cause once i hit the edge wen i put a basic limitation on it, it just sticks to the side as the variables in the if statement dont change wen i need them to Just thought I would let ya know where im at as I'm pretty stoked with my progress as i have really only used js for displaying and hiding elements. I just couldnt see jquery being very fun to code with as most of the raw math and code is done for you which i find great figuring out lol
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.