Jump to content

The14thGOD

Members
  • Posts

    256
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

The14thGOD's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  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
×
×
  • 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.