Jump to content

The14thGOD

Members
  • Posts

    256
  • Joined

  • Last visited

    Never

Everything posted by The14thGOD

  1. yep..didn't even think of that, I need to adjust the code to delete the file first, then upload. Never ran into the issue before because I never replaced a file the same day. Some of the code didn't work due to a server switch. I had to re-write it after I found out it wasn't working but the db was still updating. This caused it to store today's file name. Seems so easy yet I completely overlooked that. Thanks.
  2. /home/XXXXXX/domains/example.domain.com/html/zips/filename_12-08-02.zip is the full path, and my unlink function works too. If I remove the BASE_ROOT var I start getting php errors of non existing directories as expected including the unlink function. I've also added the max filesize to the form (found a reported bug, but it was an older version of PHP (current: 5.3.13)).
  3. Yeah, that's where I'm checking but the file doesn't exist there.
  4. crap, sorry, forgot, permissions are all correct too **edit** as well as php ini settings, the file is only 26kb and the correct encryptype is on the form(s)
  5. Just as title says, the function returns 1 but when I check the directory it is empty. I moved servers a few months ago and since it's a personal project I didn't bother checking it beyond is everything showing up. Here's the function that handles the file handling: //config define('BASE_ROOT', getenv("DOCUMENT_ROOT")); //project class public function upload_file($file){ $accepted_file_types = array('zip','rar','html','css','js','php','sql','xml','txt'); $ext = explode('.',$file['name']); if(array_search($ext[1],$accepted_file_types) !== false) { $uploaddir = BASE_ROOT."/zips/"; $safename = $this->sanitize_url_string($ext[0]); $file_dir = "$uploaddir".$safename.'_'.date('y-m-d').".$ext[1]"; move_uploaded_file($file['tmp_name'], "$file_dir"); //rename file to be accessed from root $this->old_path = $this->path; $this->path = str_replace(BASE_ROOT,"",$file_dir); } } public function sanitize_url_string($str){ $str = preg_replace('/[^-a-zA-Z0-9_]/','-',$str); $str = preg_replace('/[-]{2,}/','-',$str); $str = strtolower($str); return $str; } I'm hosting on media temple, and the BASE_ROOT is accurate, so I'm not sure where the file is if it's not in the zips folder... Any ideas? Thanks, Justin
  6. I decided to drop what I had and try to approach it a bit differently, found a NOT IN clause, this seems to do the trick (for now knowing my luck...) SELECT u.id,u.client_id,u.name FROM users AS u RIGHT JOIN projects AS p ON p.id = 4 WHERE u.id NOT IN (SELECT user_id FROM project_relationships WHERE project_id = 4) AND p.client_id = u.client_id AND u.status='enabled'
  7. Users: id | client_id | name 1 | 1 | justin 2 | 2 | laura 3 | 1 | jayjay clients: id | name 1 | client 1 2 | client 2 projects: id | client_id | name | 1 | 1 | project 1 project_relationships: id | user_id | client_id | project_id 1 | 1 | 1 | 1 There's a lot more columns, but nothing else that is related to this query in particular. This query almost worked.. but it basically matches every other one (so it still pulls in both records), worked when 'justin' was assigned to the project and 'jayjay' wasn't. I'm assuming it can be written better though w/ less crap. SELECT n.id,n.client_id,n.name FROM ( SELECT u.id,u.client_id,u.name FROM users AS u RIGHT JOIN projects AS p ON p.client_id = u.client_id WHERE p.id = 4 AND u.status='enabled' ) AS n INNER JOIN projects as j ON j.client_id = n.client_id INNER JOIN project_relationships AS pr ON pr.client_id = n.client_id WHERE pr.project_id = j.id AND pr.user_id != n.id
  8. I'm having troubles figuring out how to do this (never done this before) and I think I'm also having a brain fart at the same time. Basically I'm trying to grab people who are on a project, and exclude those from another query to get others who are tied to the client but not already on the project. Here's my query so far.. SELECT DISTINCT n.id,n.name FROM ( SELECT u.id,u.client_id,u.name FROM users AS u RIGHT JOIN projects AS p ON p.client_id = u.client_id WHERE p.id = 4 AND u.status='enabled' ) AS n INNER JOIN project_relationships AS pr ON pr.user_id = n.id WHERE pr.project_id = 4 AND n.id != pr.user_id The results are nothing, the inner query: SELECT u.id,u.client_id,u.name FROM users AS u RIGHT JOIN projects AS p ON p.client_id = u.client_id WHERE p.id = 4 AND u.status='enabled' Results in both users tied to client: id | name 1 | justin - THIS is the only user on the project 2 | jayjay So basically, i want to grab jayjay only. Sorry if I'm not explaining this well, I'm not exactly a mysql expert.. Thanks for any and all help, Justin *edited for readability*
  9. yeah, i hate when that happens, hopefully it'll be of use to someone in the future (came back to mark topic solved as I forgot to)
  10. nvm, found a different way to approach it, in case anyone runs into a similar issue, here is the solution: http://stackoverflow.com/a/5976031
  11. I apologize if I am using the wrong terminology here... I am trying to take an image that is dragged and dropped and then uploading the image to a server to do other things with it. I've found very generic example(s) that can just move the file, but I need to be able to manipulate it on the server. AJAX cut-out code: var xhr = new XMLHttpRequest(); if(xhr.upload && file.type == 'image/jpeg' || file.type == 'image/png'){ xhr.open('POST', 'path/to/script.php', true); xhr.setRequestHeader('X_FILENAME', file.name); xhr.send(file); } The above part works but when I try to manipulate it with PHP it doesn't see it as a typical $_FILES variable. Ideally I would like to get it to be like that, if not I understand I will have to change stuff. Here is my PHP that handles the above call: <?php $slide = new Slide(); //echo gettype($_SERVER['HTTP_X_FILENAME']); //str $file = file_get_contents('php://input'); $image = base64_decode($file); if($slide->add_image_to_slide($_GET['sid'],$image)){ echo 'yay'; }else{ echo $slide->error; } Object Code: <?php public function add_image_to_slide($id,$image){ //Verify image before proceeding forward $accepted_file_types = array('jpg','png'); $ext = explode('.',$image['name']); if(array_search($ext[1],$accepted_file_types) !== false) { //variables $this->id = $id; $this->select_slide($this->id); //make sure that the folders for the images to go actually exist, if not, create them $this->create_folders(); $this->generate_thumbnail($image); $this->thumbnail = $this->upload_directory.$this->rand_id.'_thumb_'.$this->filename; $this->full_img = $this->upload_directory.$this->rand_id.'_'.$this->filename; // thumbnail is moved automatically by function above, just move full image move_uploaded_file($image['tmp_name'], BASE_ROOT.'/'.$this->full_img); if($stmt = $this->_db->prepare('UPDATE slides SET full_img = ? , thumbnail = ? WHERE id = ?')){ $stmt->bind_param('ssi',$this->full_img,$this->thumbnail,$id); $stmt->execute(); $stmt->close(); return true; } return false; } $this->error = 'File Extension Error: .jpg, .png allowed only'; return false; } Right now it's skipping straight to $this->error since it's not an image object. I'm not really sure what to pursue from here. I did try this line once but it also skipped to the error line: <?php $image = createimagefromstr(file_get_contents('php://input')); Any help would be greatly appreciated! Thanks, Justin
  12. I don't know why but I'm failing hard at GoogleFu today. I can't find a tutorial on how to store a session id in a cookie and then call it on the server. session_id says it replaces the cookie it makes if you set the id via session_id, even if it's the same id...but I'm not sure if that really matters. Can anyone help point me in the right direction to a good tutorial/give me some insight on this subject? I want to store the session id in a cookie to keep a user logged in for 2 weeks or so (unless they log out of course). I did find some tutorials on how to re-route the session handlers for open/close/read/write session functions which allow me to store the session in a database. Is this what I want? Sorry for the newbie question, Thanks, Justin
  13. update: ok i narrowed it down... it's gotta be something to do with the way json handles the code that is passed from PHP to javascript, I changed it to output 'code here' and it worked
  14. I should clarify, the success function never runs either, however if I reload the page, the new entry is there.
  15. Just a heads up, my OOP skills are in development so sorry for the roughness of things...(any tips always appreciated!) I'm basically making my own little repository site that will have snippets (for quick copy paste anywhere) (I know there are other services, but mine is a little different and needs to be private). I'll try to just post the necessary code: HTML trying to pass: <p><br /><span class="something">Hey buddy</span></p> Javascript/JQuery: //send info $.ajaxFileUpload({ url:'./upload_zip.php', secureuri:false, fileElementId:'form_zip', dataType: 'json', data: {... 'description': htmlEntities($('#modularContent form textarea[name="description"]').val())...}, success:function(data, status){ var html = ... html+= ...'<div class="description"><p>'+data.description+'<br /><br />';... $('#list').append(html); ... $('#modularOverlay,#modularContent').remove(); }, error:function(data, status, e){ alert(e); } ... function htmlEntities(str) { return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); } //found via: http://css-tricks.com/snippets/javascript/htmlentities-for-javascript/ PHP: <?php //Start object and modify initial values public function __construct($title,$description,$url,$snippet){ ... if($this->snippet == 'yes'){ $this->handle_snippet(); } } public function handle_snippet(){ $code = htmlentities($this->description, ENT_QUOTES | ENT_IGNORE, 'UTF-8',false); $this->description = $code; } //returning value public function getJSON($action){ //temp fix for js breaking if remove_tag_ids is empty/null if(empty($this->remove_tag_ids)){ $this->remove_tag_ids = 'null'; } if($this->snippet == 'yes'){ $this->description = stripslashes($this->description); } switch($action){ case 'delete': //not important default: $json = array(...'description'=>$this->description...); break; return $json; } ?> POST Value: (via firebug) description: <p><br /><span class="something">Hey buddy</span></p> JSON Return value: (via firebug) description: <p><br /><span class="something">Hey buddy</span></p> DB value: <p><br /><span class=\"something\">Hey buddy</span></p> As far as error, I have no idea what the error is haha. It does not get through to the error code cause the plugin tosses an error b4 that (using an ajaxUpload plugin http://www.phpletter.com/Our-Projects/AjaxFileUpload/, (this does not affect the upload, it uploads just fine, but it tosses an error for some reason)). Anyone have any insights/ideas? Thanks for any and all help, Justin
  16. This seems to work: @media only screen and (max-device-width: 480px),only screen and (max-device-width: 800px) and (-webkit-min-device-pixel-ratio: 1.5) and (orientation:landscape){ However it won't target lower end android devices, and I'm not sure if android will go to a 2 pixel ratio. This should catch a large amount of the users out there though.
  17. First time I've done a mobile site that adapts to the screen size and I am having problems with media queries. I've gone to about 30 sites and none solve the issue. Basically the set up I need is: iPad orientation:landscape and desktop = style set 1 ipad orientation:portrait = style set 2 iphone+android = style set 3 Actual media quries: @media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {/*styles*/} @media only screen and (max-device-width: 480px){} The issue with this is if you load the site in landscape on android it reverts to the desktop version of the site since the resolution is 800px wide. (I don't know why but iPhone does not break...it still loads the mobile site. So then I get the brilliant idea to do: @media only screen and (max-device-width: 480px), only screen and (max-device-width: 800px) and (orientation:landscape){ Works everywhere except if you view the site on the iPad on landscape, then it pulls in the mobile style set (3). I have no idea what is going on... Any help is always appreciated, Thanks, Justin
  18. Thanks! I think I found a good tutorial on it. Looks simple enough. (for those who may stumble here: http://www.potstuck.com/2009/01/08/php-dependency-injection/ )
  19. I'm having difficulties forming a google query to get a result I want. Basically I want to have a db connection used by other classes. Someone showed me a month ago about a way to pass a db object to the class but said it wasn't the best method. So I'm trying to find a tutorial to get me on the right track. I'm new to OOP so if this sounds stupid I apologize. This is what I'm currently doing (passing the db connection to the object): <?php //config file $db = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME); //page $user = new user($db); //user class public function __construct($db){ $this->db = $db; } ?> Any help in the right direction would be greatly appreciated. Also if anyone knows any good books to purchase on walking through small projects that would be awesome. I bought PHP5 Objects, Patterns and Practices but that didn't really walk through a project. It did get to some complicated things (for me) that I think I can understand once I get smaller projects under my belt. Thanks, Justin
  20. well after coming back i remembered why it's not going to work, wordpress sometimes stores & as & and other times &, just had to change it to the right one to match correctly.
  21. Some people have [L] in front of the practice area because they are the group leader so it just runs automatically to make sure it's not in the string. The example I gave just happened to not have it. Sorry, should of removed it to avoid confusion. Basically I'm calling the function: $member = checkPracticeAreas2($practice_areas,$cats); If it's returns true I do some other stuff to it. For some reason whenever [HC] or [LE] is to be matched it always returns false. (It should return true 5-30 times depending on category).
  22. So I have a really complicated search/filter system going on here and am trying to get a couple items to work. For some reason they are not. The only thing I can see that is common between the two not working examples is the & character. There are multiple practice areas (the [XX] is there for tying specialties to practice areas which has to be editable by client). Here I am just trying to get the practice area and not anything else. It should be pretty straight forward. I had it working before without the brackets so not sure why it's not working now. Should be pretty straight forward. <?php /* Example print_r of $cats = Array ( [0] => [CL]Commercial Litigation [1] => [PL]Product Liability/Mass Tort [2] => [HC]Health Care Law & Consulting [3] => [LE]Labor & Employment [4] => [bG]Business Group ) Example $practice_areas = Commercial Litigation| Health Care Law & Consulting Working $ps examples = [CL] || [PL] || [bG] Not-working $ps examples = [HC] || [LE] */ function checkPracticeAreas2($practice_areas,$cats){ $member = false; //$practice_areas = str_replace('&','&#038;',$practice_areas); $practice_areas = str_replace('[L]','',$practice_areas);//remove leader attr $practice_areas = explode('|',$practice_areas); //find which practice area $ps = $_GET['ps']; $plus = stripos($ps,'+');//if specialty is present, just get the practice_area intials if($plus !== false){ $xpld = explode('+',$ps); $ps = $xpld[0]; } for($i=0;$i<sizeof($cats);$i++){ $isAbbr = stripos($cats[$i],urldecode($ps)); if($isAbbr !== false){ $the_practice = substr($cats[$i],4); break; } } for($i=0;$i<sizeof($practice_areas);$i++){ $isPracticeArea = stripos($practice_areas[$i],$the_practice); if($isPracticeArea !== false){ $member = true; break; } } return $member; } ?> I don't know if I've started at this for too long or what I'm missing...but I'm just running in circles. Thanks for any and all help, Justin
  23. Yea, its definitely confusing. I've read a good amount of tutorials and done basic OOP stuff (nothing with DB though). I feel I have a decent understanding but obviously not perfect. Putting it to use will change that significantly though. Thanks again for your help =)
  24. Nope, I just have the O'Reilly cookbook that has a chapter about OOP. I found Zandstra's book on Amazon though, in que, thx. Also just switched all the code and it works. Makes a lot more sense once I trashed that db class. Was stuck trying to figure out how the classes all talked to each other to use the dblink. But yea, passing the db variable every time seems bad
  25. sweet, I'll try this when I get home in a bit (on my way out). Would you mind hooking me up with a link or a proper Google query for the better/advanced way? I don't mind researching on my own, I just have a hard time formulating the right query. I'll let you know how this goes after I fix it, thx =)
×
×
  • 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.