Jump to content

harkly

Members
  • Posts

    264
  • Joined

  • Last visited

Everything posted by harkly

  1. I am attempting to use the croppic, http://www.jqueryrain.com/?S4PWDcPG, to modify images and want to be able to control the name of the file being produced. I also want to be able to save the name to my database. My quess is that I have to pass a variable to the img_save_to_file.php but not sure how to do that, I've tried using sessions but could not get that to work. Is there any other way that I could try but am not thinking of. A bit confused any direction would be appreciated. <?php /* * !!! THIS IS JUST AN EXAMPLE !!!, PLEASE USE ImageMagick or some other quality image processing libraries */ $imagePath = "temp/"; $allowedExts = array("gif", "jpeg", "jpg", "png", "GIF", "JPEG", "JPG", "PNG"); $temp = explode(".", $_FILES["img"]["name"]); $extension = end($temp); //Check write Access to Directory if(!is_writable($imagePath)){ $response = Array( "status" => 'error', "message" => 'Can`t upload File; no write Access' ); print json_encode($response); return; } if ( in_array($extension, $allowedExts)) { if ($_FILES["img"]["error"] > 0) { $response = array( "status" => 'error', "message" => 'ERROR Return Code: '. $_FILES["img"]["error"], ); } else { $filename = $_FILES["img"]["tmp_name"]; list($width, $height) = getimagesize( $filename ); move_uploaded_file($filename, $imagePath . $_FILES["img"]["name"]); $response = array( "status" => 'success', "url" => $imagePath.$_FILES["img"]["name"], "width" => $width, "height" => $height ); } } else { $response = array( "status" => 'error', "message" => 'something went wrong, most likely file is to large for upload. check upload_max_filesize, post_max_size and memory_limit in you php.ini', ); } print json_encode($response); ?>
  2. Edit: upload blob not blog I would like to use the following code to crop images that will be uploaded to mySql with PHP. I just cannot figure out how to call the blob so I can use it. Can someone help me with this? Using the code from here: http://hongkhanh.github.io/cropbox/ HTML <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>Crop Box</title> <link rel="stylesheet" href="style.css" type="text/css" /> <style> .container { position: absolute; top: 10%; left: 10%; right: 0; bottom: 0; } .action { width: 400px; height: 30px; margin: 10px 0; } .cropped>img { margin-right: 10px; border:1px solid green: } </style> </head> <body> <script src="../cropbox.js"></script> <div class="container"> <div class="imageBox"> <div class="thumbBox"></div> <div class="spinner" style="display: none">Loading...</div> </div> <div class="action"> <input type="file" id="file" style="float:left; width: 250px"> <input type="button" id="btnCrop" value="Crop" style="float: right"> <input type="button" id="btnZoomIn" value="+" style="float: right"> <input type="button" id="btnZoomOut" value="-" style="float: right"> </div> <div class="cropped"></div> <script type="text/javascript"> window.onload = function() { var options = { imageBox: '.imageBox', thumbBox: '.thumbBox', spinner: '.spinner', imgSrc: 'avatar.png' } var cropper = new cropbox(options); document.querySelector('#file').addEventListener('change', function(){ var reader = new FileReader(); reader.onload = function(e) { options.imgSrc = e.target.result; cropper = new cropbox(options); } reader.readAsDataURL(this.files[0]); this.files = []; }) document.querySelector('#btnCrop').addEventListener('click', function(){ var img = cropper.getDataURL(); document.querySelector('.cropped').innerHTML += '<img src="'+img+'">'; }) document.querySelector('#btnZoomIn').addEventListener('click', function(){ cropper.zoomIn(); }) document.querySelector('#btnZoomOut').addEventListener('click', function(){ cropper.zoomOut(); }) }; </script> </body> </html> /** * Created by ezgoing on 14/9/2014. */ 'use strict'; var cropbox = function(options){ var el = document.querySelector(options.imageBox), obj = { state : {}, ratio : 1, options : options, imageBox : el, thumbBox : el.querySelector(options.thumbBox), spinner : el.querySelector(options.spinner), image : new Image(), getDataURL: function () { var width = this.thumbBox.clientWidth, height = this.thumbBox.clientHeight, canvas = document.createElement("canvas"), dim = el.style.backgroundPosition.split(' '), size = el.style.backgroundSize.split(' '), dx = parseInt(dim[0]) - el.clientWidth/2 + width/2, dy = parseInt(dim[1]) - el.clientHeight/2 + height/2, dw = parseInt(size[0]), dh = parseInt(size[1]), sh = parseInt(this.image.height), sw = parseInt(this.image.width); canvas.width = width; canvas.height = height; var context = canvas.getContext("2d"); context.drawImage(this.image, 0, 0, sw, sh, dx, dy, dw, dh); var imageData = canvas.toDataURL('image/png'); return imageData; }, getBlob: function() { var imageData = this.getDataURL(); var b64 = imageData.replace('data:image/png;base64,',''); var binary = atob(b64); var array = []; for (var i = 0; i < binary.length; i++) { array.push(binary.charCodeAt(i)); } return new Blob([new Uint8Array(array)], {type: 'image/png'}); }, zoomIn: function () { this.ratio*=1.1; setBackground(); }, zoomOut: function () { this.ratio*=0.9; setBackground(); } }, attachEvent = function(node, event, cb) { if (node.attachEvent) node.attachEvent('on'+event, cb); else if (node.addEventListener) node.addEventListener(event, cb); }, detachEvent = function(node, event, cb) { if(node.detachEvent) { node.detachEvent('on'+event, cb); } else if(node.removeEventListener) { node.removeEventListener(event, render); } }, stopEvent = function (e) { if(window.event) e.cancelBubble = true; else e.stopImmediatePropagation(); }, setBackground = function() { var w = parseInt(obj.image.width)*obj.ratio; var h = parseInt(obj.image.height)*obj.ratio; var pw = (el.clientWidth - w) / 2; var ph = (el.clientHeight - h) / 2; el.setAttribute('style', 'background-image: url(' + obj.image.src + '); ' + 'background-size: ' + w +'px ' + h + 'px; ' + 'background-position: ' + pw + 'px ' + ph + 'px; ' + 'background-repeat: no-repeat'); }, imgMouseDown = function(e) { stopEvent(e); obj.state.dragable = true; obj.state.mouseX = e.clientX; obj.state.mouseY = e.clientY; }, imgMouseMove = function(e) { stopEvent(e); if (obj.state.dragable) { var x = e.clientX - obj.state.mouseX; var y = e.clientY - obj.state.mouseY; var bg = el.style.backgroundPosition.split(' '); var bgX = x + parseInt(bg[0]); var bgY = y + parseInt(bg[1]); el.style.backgroundPosition = bgX +'px ' + bgY + 'px'; obj.state.mouseX = e.clientX; obj.state.mouseY = e.clientY; } }, imgMouseUp = function(e) { stopEvent(e); obj.state.dragable = false; }, zoomImage = function(e) { var evt=window.event || e; var delta=evt.detail? evt.detail*(-120) : evt.wheelDelta; delta > -120 ? obj.ratio*=1.1 : obj.ratio*=0.9; setBackground(); } obj.spinner.style.display = 'block'; obj.image.onload = function() { obj.spinner.style.display = 'none'; setBackground(); attachEvent(el, 'mousedown', imgMouseDown); attachEvent(el, 'mousemove', imgMouseMove); attachEvent(document.body, 'mouseup', imgMouseUp); var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel'; attachEvent(el, mousewheel, zoomImage); }; obj.image.src = options.imgSrc; attachEvent(el, 'DOMNodeRemoved', function(){detachEvent(document.body, 'DOMNodeRemoved', imgMouseUp)}); return obj; };
  3. What I don't understand if that it was all working fine before last Friday and then nothing. It won't send to any email account I have people from different ones trying it and nothing as long as it has the wlsingles.com url in it even if its an email address from there won't work $headers = 'From: WLSingles <email@WLSingles.com>' ; So say it is got listed somewhere what do I do?? Start all over again?? A different domain name?? So ready to tear my hair out!
  4. I am trying this code out on 2 different servers and it definity stops when I enter the one particular url - how do I check why?
  5. I using this simple code to send a test message if I put in my url it won't send, more like it sends but never gets received no matter what email account I use. If I put in another url it works fine. Does anyone know what causes that and how I can go about fixing it?? in this code I added a '2' to the url and it works, take the 2 out - nothing <?php mail('me@yahoo.com', 'Account Info', 'is this working? www.wlsingle2s.com');?>
  6. That's where I am getting a bit confused. All my code works and I am not getting any MySql errors and any fields that require user input are handled within that code. I wasn't going to put any error handling other then not to show but everything I read tells me I need to
  7. So I should handle them in each and every Select, Update ...?
  8. I have a site that is going to go public and I am wondering what is the status quo on handling possible errors? I have them turned off so they won't show and they will be sent to an email but what about on the user end? What should I have happen so the user won't get confused??? This is probably a stupid question but is there a way to check the page for an over-all-error vs putting an error check in every Select & Update? What I would like to do, if possilbe: page opens - there is an error - kicks user to a new page - emails error to me. I have it all working just wondering if I can do some generic check and then execute everything.
  9. Never mind I got it Not sure if this is a regex issue or a preg_match code issue Have this function and I cannot use the @ or the % in a new password function newPswdChar($newPswd) { if (preg_match('/^[a-z0-9@!#%]+$/i',$newPswd)) return FALSE; else return TRUE; } But goes thru the Javascript check fine var alphaExpression = /^[a-z0-9@!%#]+$/i; if(!form.newPswd.value.match(alphaExpression)) { alert("Error: Invalid characters where used!"); form.newPswd.focus(); return false; } I just want to allow letters, numbers and @ ! % #. I looked and looked at the regex stuff and it seems to point to me having it correct. Can someone help me with this?
  10. Thanks! New there was something, Googling the wrong terms
  11. I have limited the upload size in my php.ini but I want a message for the user so they no that the size was to large. Is there anyway to do this?
  12. When dealing with numbers do I need to implement all the security? On in-putting into my DB I have all numbers validating, with a case statement, and I use prepared statements. So when pulling number data do I need to sanitize it as well? The types are smallint() or tinyint()
  13. Also have one more question I am using mysqli! and then filtering the data on input do I really need to escape it as well? I ask this becuase when escaping it is messing up the format of the text when there is a break in it.
  14. I am working on adding security to my code. This is new to me and I am confused at which one to use. The numbers, email and pswd are all explanatory its the text fields that are confusing me. So I have a variety of text fields where the user can input what they want. I want to be able to add in a variety of characters but want it to be secure as well. I want to be able to use the "&" so I think I want All the text fields will be used for descriptions or notes. Also, how secure, if at all, is this function? It was a very earlier attempt at security function check_input($data) { $data = trim($data); $data = htmlspecialchars($data); return $data; }
  15. I would like to get into the OOP but I can't on this project. I had this function that I had help converting from mysql to mysqli, is this not the using the procedural API for the mysqli extension? and would these other functions not working the same?? Before:: function usedEmail($email) { $sql_check = mysql_query("select email from user where email='".$email."'") or die(mysql_error()); if (mysql_num_rows($sql_check)) return FALSE; else return TRUE; } After:: function usedEmail($email, MySQLi $db) { $bResult = false; if ($sql = $db->prepare("SELECT email FROM user WHERE email=?")) { $sql->bind_param('s', $email); $sql->execute(); $sql->store_result(); $bResult = $sql->num_rows > 0; $sql->close(); } return $bResult; }
  16. Getting a this is the line it is referencing $result = $mysqli->query($sql); the function it is in function get_zip_point($zip) { $sql = "SELECT lat, lon from zip_code WHERE zip_code='$zip'"; $result = $mysqli->query($sql); if (!$result) { $this->last_error = $mysqli->error(); return false; } else { $row = $result->fetch_array; $result->close(); return $row; } } the function is is being called by this other function, 3rd line down function get_zips_in_range($zip, $range, $sort=1, $include_base) { $this->chronometer(); // start the clock $details = $this->get_zip_point($zip); // base zip details if ($details == false) return false; // This portion of the routine calculates the minimum and maximum lat and // long within a given range. This portion of the code was written // by Jeff Bearer (http://www.jeffbearer.com). This significanly decreases // the time it takes to execute a query. My demo took 3.2 seconds in // v1.0.0 and now executes in 0.4 seconds! Greate job Jeff! // Find Max - Min Lat / Long for Radius and zero point and query // only zips in that range. $lat_range = $range/69.172; $lon_range = abs($range/(cos($details[0]) * 69.172)); $min_lat = number_format($details[0] - $lat_range, "4", ".", ""); $max_lat = number_format($details[0] + $lat_range, "4", ".", ""); $min_lon = number_format($details[1] - $lon_range, "4", ".", ""); $max_lon = number_format($details[1] + $lon_range, "4", ".", ""); $return = array(); // declared here for scope $sql = "SELECT zip_code, lat, lon FROM zip_code "; if (!$include_base) $sql .= "WHERE zip_code <> '$zip' AND "; else $sql .= "WHERE "; $sql .= "lat BETWEEN '$min_lat' AND '$max_lat' AND lon BETWEEN '$min_lon' AND '$max_lon'"; $result = $mysqli->query($sql); if (!$result) { // sql error $this->last_error = $mysqli->error(); return false; } else { while ($row = $result->fetch_row()) { // loop through all 40 some thousand zip codes and determine whether // or not it's within the specified range. $dist = $this->calculate_mileage($details[0],$row[1],$details[1],$row[2]); if ($this->units == _UNIT_KILOMETERS) $dist = $dist * _M2KM_FACTOR; if ($dist <= $range) { $return[str_pad($row[0], 5, "0", STR_PAD_LEFT)] = round($dist, $this->decimals); } } mysql_free_result($r); } // sort array switch($sort) { case _ZIPS_SORT_BY_DISTANCE_ASC: asort($return); break; case _ZIPS_SORT_BY_DISTANCE_DESC: arsort($return); break; case _ZIPS_SORT_BY_ZIP_ASC: ksort($return); break; case _ZIPS_SORT_BY_ZIP_DESC: krsort($return); break; } $this->last_time = $this->chronometer(); if (empty($return)) return false; return $return; }
  17. I have converted my mysql to mysqli and am working on converting some functions. My question - Can I not just convert the mysql to mysqli? This is the full code: class zipcode_class { var $last_error = ""; // last error message set by this class var $last_time = 0; // last function execution time (debug info) var $units = _UNIT_MILES; // miles or kilometers var $decimals = 2; // decimal places for returned distance function get_zip_point($zip) { // This function pulls just the lattitude and longitude from the // database for a given zip code. $sql = "SELECT lat, lon from zip_code WHERE zip_code='$zip'"; $r = $mysqli->query($sql); if (!$r) { $this->last_error = mysql_error(); return false; } else { $row = mysql_fetch_array($r); mysql_free_result($r); return $row; } } function calculate_mileage($lat1, $lat2, $lon1, $lon2) { // used internally, this function actually performs that calculation to // determine the mileage between 2 points defined by lattitude and // longitude coordinates. This calculation is based on the code found // at http://www.cryptnet.net/fsp/zipdy/ // Convert lattitude/longitude (degrees) to radians for calculations $lat1 = deg2rad($lat1); $lon1 = deg2rad($lon1); $lat2 = deg2rad($lat2); $lon2 = deg2rad($lon2); // Find the deltas $delta_lat = $lat2 - $lat1; $delta_lon = $lon2 - $lon1; // Find the Great Circle distance $temp = pow(sin($delta_lat/2.0),2) + cos($lat1) * cos($lat2) * pow(sin($delta_lon/2.0),2); $distance = 3956 * 2 * atan2(sqrt($temp),sqrt(1-$temp)); return $distance; } function get_zips_in_range($zip, $range, $sort=1, $include_base) { // returns an array of the zip codes within $range of $zip. Returns // an array with keys as zip codes and values as the distance from // the zipcode defined in $zip. $this->chronometer(); // start the clock $details = $this->get_zip_point($zip); // base zip details if ($details == false) return false; // This portion of the routine calculates the minimum and maximum lat and // long within a given range. This portion of the code was written // by Jeff Bearer (http://www.jeffbearer.com). This significanly decreases // the time it takes to execute a query. My demo took 3.2 seconds in // v1.0.0 and now executes in 0.4 seconds! Greate job Jeff! // Find Max - Min Lat / Long for Radius and zero point and query // only zips in that range. $lat_range = $range/69.172; $lon_range = abs($range/(cos($details[0]) * 69.172)); $min_lat = number_format($details[0] - $lat_range, "4", ".", ""); $max_lat = number_format($details[0] + $lat_range, "4", ".", ""); $min_lon = number_format($details[1] - $lon_range, "4", ".", ""); $max_lon = number_format($details[1] + $lon_range, "4", ".", ""); $return = array(); // declared here for scope $sql = "SELECT zip_code, lat, lon FROM zip_code "; if (!$include_base) $sql .= "WHERE zip_code <> '$zip' AND "; else $sql .= "WHERE "; $sql .= "lat BETWEEN '$min_lat' AND '$max_lat' AND lon BETWEEN '$min_lon' AND '$max_lon'"; $r = mysql_query($sql); if (!$r) { // sql error $this->last_error = mysql_error(); return false; } else { while ($row = mysql_fetch_row($r)) { // loop through all 40 some thousand zip codes and determine whether // or not it's within the specified range. $dist = $this->calculate_mileage($details[0],$row[1],$details[1],$row[2]); if ($this->units == _UNIT_KILOMETERS) $dist = $dist * _M2KM_FACTOR; if ($dist <= $range) { $return[str_pad($row[0], 5, "0", STR_PAD_LEFT)] = round($dist, $this->decimals); } } mysql_free_result($r); } // sort array switch($sort) { case _ZIPS_SORT_BY_DISTANCE_ASC: asort($return); break; case _ZIPS_SORT_BY_DISTANCE_DESC: arsort($return); break; case _ZIPS_SORT_BY_ZIP_ASC: ksort($return); break; case _ZIPS_SORT_BY_ZIP_DESC: krsort($return); break; } $this->last_time = $this->chronometer(); if (empty($return)) return false; return $return; } }
  18. There really not that bad, break them into parts SELECT FROM LEFT JOIN ON WHERE For the SELECT put every field you want to pull info out, you do need to fully qualify them = tableName.fieldName. Here is an example of mine, I am just pulling info from 2 tables SELECT user.userID, user.gender, user.genderPref, user.city, user.state, photos.photo_1 FROM is the the first table, I use my most important table here FROM user LEFT JOIN - I view it a just another FROM, pretty sure I will get slammed for that, but I like to keep things simple, defintely look more into it once you get the gist LEFT JOIN photos ON is the where the 2 tables connect, here I am connecting user w/ photos based on the userID, they are identical in both tables ON user.userID = photos.userID I am going to use 3 more LEFT JOINS becuase I need them for my conditions in my WHERE clause LEFT JOIN about_me ON user.userID = about_me.userID LEFT JOIN bkgd ON user.userID = bkgd.userID LEFT JOIN appearance ON user.userID = appearance.userID WHERE is the place you put all your conditions for all tables, use the "AND" to separate them WHERE user.userID !='$clientID' AND user.bd_year <= $year1 AND user.bd_year >= $year2 AND user.gender =$genderPref AND user.genderPref = $gender AND user.exp_date) "; Just take your tables and plug them in
  19. I have a list, can be any length, and I need to be able to pull out a specific variable. I had it working in a form but it was nested in another form, just learned that I cannot do that so I need help with how to get what I need done. So say my list consist of 3 names John Jane Betty I click on a link to 'block' John from the list, what is the best way to do that? This is what I had: <form action='' method='POST' name='blockuser' id='blockuser'> <input type='hidden' name='block2' value='$sender' /> <input type='image' value='Block' src='delete.png' title='Block'> </form> if($_POST['block2']){ echo "block $sender "; } I was thinking I need to put it in an array but this isn't working either <input type='hidden' name='block2[]' value='$id' /> <input type='image' value='Block' src='delete.png' title='Block'> $my_array2 = $_POST['block2']; if($_POST['block2']){ $totalIDs = count($my_array2); for ( $i=0; $i < $totalIDs; $i++ ) { $sql2 = mysql_query("SELECT sender FROM nudges WHERE id='$my_array2[$i]'"); while($r = mysql_fetch_array($sql2)) { $sender=$r['sender']; echo "block $sender "; } // END while } // END for } // END if($_POST['block2']) what I get back is what I need is Maybe going with an array is not the way to do it, can someone help me out?
  20. Yes, you can. Use an "if" statement
  21. Looks like you are searching on different tables and not databases, correct? To do the tables you want to use "Joins" SELECT FROM LEFT JOIN ON
  22. harkly

    query

    Got it to work (NOT IN)and so pissed at myself!!! Days on this issue and it turns out that I was not putting the code in both my if and else so it didn't appear to be working!!! Thanks for all the help!
  23. harkly

    query

    How else can I achieve the results that I am looking for? I was trying to use NOT IN but could not get that to work in the large search WHERE userID NOT IN (SELECT blockUser.blockID FROM blockUser WHERE blockUser.blockUserID = '$clientID')
×
×
  • 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.