Jump to content

grasshopper31

Members
  • Content count

    14
  • Joined

  • Last visited

Community Reputation

0 Neutral

About grasshopper31

  • Rank
    Member
  1. grasshopper31

    mysqli query problem

    FIXED: I just had to call the _db() method first before $this->_id which makes sense i knew it was something obvious and that i just irritated looking in the wrong place. function __construct(){ $this->_db(); //load global variables $this->_id = $this->_pageSelect(); $this->_year = date('Y'); $this->_url = 'http://localhost/'; $this->_www = explode('core', __DIR__); #get abspath to rootdir #TODO: find a better method $this->_www = $this->_www[0]; echo $this->_id; // load required methods $this->_loadSettings(); $this->_loadContent(); }
  2. grasshopper31

    mysqli query problem

    Changing to trigger_error() seems like a fine advice and it just makes sense, and there is no problem with my db connection for when I use _loadSettings(); it works. Also when i remove the if statements within _pageStatus(); so that the function does not have affect the script at all. I can retrieve data from db using $this->_db(). Also after adding the code you suggested in my _db() function does not give me the error that is not an object. So something must be contradicting in the script when i add this to the _pageStatus() method in the file or maybe im just doing this using the wrong php ways. EDIT: when i visit my home "localhost" it seems to work just fine no errors, the problem is when i switch to other pages thru ?id= but again it does work and retrieves data normally when i remove the code below. if($result = $this->_db->query($sql)){ if($result->num_rows > 0){ while ($status = $result->fetch_object()) { return $status; } return $status; $result->close(); } else { return 404; } }
  3. grasshopper31

    mysqli query problem

    yes, the script grabs data from db for other things using $this->_db.. here is the file. <?php if(!defined('ACCESS_CORE')){ echo 'Not today..'; exit; } class mod_global{ protected $_db; var $_id; var $_www; var $_url; public $_settings; public $_page; public $_year; protected $_status; function __construct(){ //load global variables $this->_id = $this->_pageSelect(); $this->_year = date('Y'); $this->_url = 'http://localhost/'; $this->_www = explode('core', __DIR__); #get abspath to rootdir #TODO: find a better method $this->_www = $this->_www[0]; echo $this->_id; // load required methods $this->_db(); $this->_loadSettings(); $this->_loadContent(); } protected function _db(){ $db = parse_ini_file('../contra.conf'); $this->_db = new mysqli($db['host'], $db['user'], $db['pass'], $db['name']); if ($this->_db->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } } protected function _pageSelect(){ #user may enter a nicknamed pages -> data, Apps or a numbered page -> data if(count($_GET) > 0 && !empty($_GET['id']) && $_GET['id'] !== 0){ //a request, id isnt empty or 0 $id = $this->_inputCheck('id', $_GET['id']); //filter.. alphanumeric only if(!is_numeric($id) && $this->_pageStatus('alpha', $id) !== 404){ $real_id = $id; } else if(is_numeric($id) && $this->_pageStatus('num', $id) !== 404){ $real_id = $id; } } else { //home requested $real_id = 0; } return $real_id; } protected function _pageStatus($option, $id){ //check if page exists, if it does return the status, or return 404 switch($option){ case 'alpha' : $sql = "SELECT status FROM pages WHERE nick = '$id'"; break; case 'num' : $sql = "SELECT status FROM pages WHERE id = '$id'"; break; } if($result = $this->_db->query($sql)){ if($result->num_rows > 0){ while ($status = $result->fetch_object()) { return $status; } return $status; $result->close(); } else { return 404; } } } protected function _inputCheck($type, $var){ switch($type){ case 'id' : $result = preg_replace("/[^a-z0-9]+/", "", $var); $result = mysql_real_escape_string($result); break; //leaves alphanumeric case 'html' : $result = mysql_real_escape_string($var); #TODO: improve the html, also sanitize in the form break; //escapes } return $result; } protected function _loadSettings(){ $sql = 'SELECT * FROM settings'; if($result = $this->_db->query($sql)){ /* fetch object array */ while ($settings = $result->fetch_object()) { $this->_settings = $settings; } /* free result set */ $result->close(); } } protected function _loadContent(){ if(!is_numeric($this->_id)){ $sql = "SELECT * FROM pages WHERE nick = '$this->_id'"; //sql for alpha nick id } else if(is_numeric($this->_id)){ $sql = "SELECT * FROM pages WHERE id = '$this->_id'"; //sql for numeric id } if($result = $this->_db->query($sql)){ /* fetch object array */ while ($pageContent = $result->fetch_object()) { $this->_page = $pageContent; } /* free result set */ $result->close(); } } } ?>
  4. grasshopper31

    trouble including html using PHP

    instead of putting html in a function how bout just take all php out and just leave the html. unless, there other reasons or other things u want to do with navbar, such having more functions.
  5. grasshopper31

    mysqli query problem

    Hello guys, i'm currently building my own cms, a personal project, and now im stucked on an error "Call to a member function query() on a non-object in.. please help after creating this function.. I know the db connection and everything else worked out because i have a similar function that works just without the switch or the numrow if statement. protected function _pageStatus($option, $id){ //check if page exists, if it does return the status, or return 404 switch($option){ case 'alpha' : $sql = "SELECT status FROM pages WHERE nick = '$id'"; break; case 'num' : $sql = "SELECT status FROM pages WHERE id = '$id'"; break; } if($result = $this->_db->query($sql)){ //<--- THE ERROR WAS ON THIS LINE. if($result->num_rows > 0){ while ($status = $result->fetch_object()) { return $status; } return $status; $result->close(); } else { return 404; } } }
  6. grasshopper31

    php pagination

    How can i add pagination with php to this script that shows photos in the site. i would want to show onyl 12 per page. i started but help me find out how to make this happen. thz in advance! $album_path = $this->dir_photos.$y.'/'.$album.'/'; $normalPhotos = scandir($album_path); /* $validPath = '/photos/2014/Building%20Season/test.jpg'; $exif = exif_read_data($validPath, 'IFD0', TRUE); if(isset($exif) == true){ if (@array_key_exists('DateTime', $exif)) { $strDate = $exif['DateTime']; @list( $idate, $itime ) = explode( ' ', trim($strDate) ); @list( $iyear, $imonth, $iday ) = explode( ':', $date ); $realDate = strtotime( "{$iyear}-{$imonth}-{i$day} {$itime}" ); if(filemtime($normalPhotos) != $realDate){ touch($normalPhotos,$realDate); } } } $picLink[$images.$file] = filemtime($normalPhotos); */ ######## /*$page = (isset($_REQUEST['p']) ? $_REQUEST['p'] : null); //get user p INPUT_ENV $currentpage = isset($page) ? (integer)$page : 1; //get current page.. null = 1 $totalImg = count($normalPhotos)-2; //scandir adds two items to array by default '.' and '..' $totalPages = ceil($totalImg / $this->imgPerPage); if (($currentpage > 0) && ($currentpage <= $totalPages)) { $start = ($currentpage-1) * $numperpage; for($i=$start;$i<=($numperpage+$start-1);$i++) { } }*/ ############ echo '<div id="photosCont">'; foreach($normalPhotos as $photos){ $loadedPhotos = $this->dir_cache.$y.'_'.$album.'_'.$photos; #FORMAT: photos/load/2014_Building Season_name.jpeg $urlPhotos = $this->dir_photos.$y.'/'.$album.'/'.$photos; #FORMAT: photos/load/2014_building season_name.jpg if($photos == '.' OR $photos == '..'){ $photos = ''; } else { if(!file_exists($loadedPhotos)){ $photoLink = 'image.php?y='.$y.'&a='.$album.'&i='.$photos; } else { $photoLink = $this->dir_cache.$y.'_'.$album.'_'.$photos; } echo '<div class="photosBlock">'. '<a href="'.$urlPhotos.'" target="_blank"><img src="'.$photoLink.'" alt="thumbnail"/></a></div>'; //'<span class="photoDate">'.$photos.'</span></div>'; } }//foreach echo '</div>'; }
  7. grasshopper31

    php gallery show 12 items per page

    In this php file im showing all the pictures in one folder (album), how can I show only 12 pictures at a time using request p, i started but dont know how to combine both together. Check where the number signs are. thanks in advance. <?php class gal_cms{ private $dir_photos = 'photos/'; private $dir_cache = 'photos/load/'; private $imgPerPage = '12'; function validImages($file){ #TODO: improve/modify according to array $ext = array('jpg','jpeg','png','gif'); if(in_array(array_pop(explode(".", $file)), $ext)){ return $image; } } function randomThumbnail($albums_location){ #TODO: finish this function //$images = scandir($albums_location); //$i = rand(2, sizeof($images)-1); $images = glob($albums_location . '*.{jpg,jpeg,png,gif}', GLOB_BRACE); $randomImage = $images[array_rand($images)]; return $randomImage; #TODO: get this image check for a thumbnail php generated then retrieve that picuture instead } function getContent(){ echo '<h2>Photo Galleries</h2>'. '<p>Here in Combbat 21, we like to capture the moments of all our memories. Whether it's during competitions or just being together as a team, we have a lot of fun times together. Time goes by really fast, so its best if you can remember all that you can. Pictures capture a moment and show them to you at a later time, reminding us of the fun seasons we had together.<br/><br/>Also check out our <a href="/">videos!</a>.</p><br/>'; #TODO: short out this algorithm if(isset($_GET['year']) AND !empty($_GET['year'])){//year input -> check input $y = $_GET['year']; if(file_exists($this->dir_photos.$y)){//if correct year input -> check for if(isset($_GET['album']) AND $_GET['album'] != ''){//year,album input -> check album input $album = $_GET['album']; if(file_exists($this->dir_photos.$y.'/'.$album)){ $p = 'photos'; } else { $p = '404'; } } else { $p = 'albums'; } } else { $p = '404'; } } else { $p = 'years'; } if($p == '404'){ $sqlError = "SELECT * FROM articles WHERE id='104'"; $result = mysql_query($sqlError) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $page = array(); $page['title'] = $row['title']; $page['content'] = $row['content']; //Be careful since content is all html echo '<h2>'.$page['title'].'</h2>'. $page['content']; } } else if($p == 'years'){ //show years $sql = "SELECT name,game_year FROM media_games ORDER BY game_year DESC"; $result = mysql_query($sql) or die(mysql_error()); $exceptions = array('2007',''); //years we did not compete while($data = mysql_fetch_array($result)){ $game_names['2007'] = ''; $game_names[$data[1]] = $data[0]; } $folders = scandir($this->dir_photos); print_r($data); Arsort($folders); //sort array by value descending order echo '<div id="gal_games">'. '<div id="gal_games_inner">'; foreach($folders as $folder){ if($folder == '.' OR $folder == '..' OR $folder == 'load'){ $forder = ''; } else { echo '<div class="gal_thumbs">'. '<a href="?year='.$folder.'">'.$game_names[$folder]. '<img src="http://combbat21.com/media/gallery/photos/thumb/'.$folder.'.jpg" alt="ThumbNail"/>'. $folder.'</a><br/>'. '</div>'; } } echo '</div></div>'; } else if($p == 'albums'){ //show albums in input:year folder $folders = scandir($this->dir_photos.'/'.$y); echo '<div id="gal_overlay"><div id="photo_content"></div></div>'; echo '<div id="gal_album">'; foreach($folders as $albumFolder){ if($albumFolder == '.' OR $albumFolder == '..'){ $albumFolder = ''; } else { $thumbnails = $this->randomThumbnail($this->dir_photos.$y.'/'.$albumFolder.'/'); //'<a href="?year='.$y.'&album='.$albumFolder.'">'.$albumFolder.'</a>'; echo ''. #TODO: remove style in img when randomthumbnail is clear '<a class="gal_albums" href="?year='.$y.'&album='.$albumFolder.'">'. '<img style="width: 130px;height:130px" src="'.$thumbnails.'" alt="THUMBNAIL"/>'. '<span class="album_name">'.$albumFolder.'</span></a>'; } } echo '</div>'; } else { $album_path = $this->dir_photos.$y.'/'.$album.'/'; $normalPhotos = scandir($album_path); /* $validPath = '/photos/2014/Building%20Season/test.jpg'; $exif = exif_read_data($validPath, 'IFD0', TRUE); if(isset($exif) == true){ if (@array_key_exists('DateTime', $exif)) { $strDate = $exif['DateTime']; @list( $idate, $itime ) = explode( ' ', trim($strDate) ); @list( $iyear, $imonth, $iday ) = explode( ':', $date ); $realDate = strtotime( "{$iyear}-{$imonth}-{i$day} {$itime}" ); if(filemtime($normalPhotos) != $realDate){ touch($normalPhotos,$realDate); } } } $picLink[$images.$file] = filemtime($normalPhotos); */ ########################### /*$page = (isset($_REQUEST['p']) ? $_REQUEST['p'] : null); //get user p INPUT_ENV $currentpage = isset($page) ? (integer)$page : 1; //get current page.. null = 1 $totalImg = count($normalPhotos)-2; //scandir adds two items to array by default '.' and '..' $totalPages = ceil($totalImg / $this->imgPerPage); if (($currentpage > 0) && ($currentpage <= $totalPages)) { $start = ($currentpage-1) * $numperpage; for($i=$start;$i<=($numperpage+$start-1);$i++) { } }*/ ###################### echo '<div id="photosCont">'; foreach($normalPhotos as $photos){ $loadedPhotos = $this->dir_cache.$y.'_'.$album.'_'.$photos; #FORMAT: photos/load/2014_Building Season_name.jpeg $urlPhotos = $this->dir_photos.$y.'/'.$album.'/'.$photos; #FORMAT: photos/load/2014_building season_name.jpg if($photos == '.' OR $photos == '..'){ $photos = ''; } else { if(!file_exists($loadedPhotos)){ $photoLink = 'image.php?y='.$y.'&a='.$album.'&i='.$photos; } else { $photoLink = $this->dir_cache.$y.'_'.$album.'_'.$photos; } echo '<div class="photosBlock">'. '<a href="'.$urlPhotos.'" target="_blank"><img src="'.$photoLink.'" alt="thumbnail"/></a><br/>'. '<span class="photoDate">'.$photos.'</span></div>'; } }//foreach echo '</div>'; } }//end of function }//end of class ?>
  8. grasshopper31

    PHP image resize help!

    i guess ill answer my question again. simply removing return $imgOld; makes the script work like a charm
  9. grasshopper31

    PHP image resize help!

    so the error is happening where return $imgOld; i know this because i switch from: return $imgOld; echo 'is on'; ################################ to: echo 'is on'; ############################### return $imgOld; and echo worked.. im using php developmental, so it will show all errors if there is any, my problem is that i dont see nor errors its just plain blank
  10. grasshopper31

    PHP image resize help!

    i want to return the img in the browser so that it can be called with img html tag, and also save the re-sized picture in a folder to save time loading the page . note that i added echo 'is on'; that is not showing up neither which should mean the problem is above that? <?php #TODO: find ways to improve quality #bmt files are not supported by this script $quality = '100'; //in imagejpeg() type function default quality = 75, min = 0, max 100 $maxW = '180'; $maxH = '180'; $dirLoad = 'photos/load/'; //thumb size dir $dirOriginal = 'photos/'; //original size dir if(isset($_GET['a']) AND isset($_GET['y']) AND isset($_GET['i'])){ $falbum = stripslashes($_GET['a']); $fyear = stripslashes($_GET['y']); $img = stripslashes($_GET['i']); } else { echo 'lol'; exit; } $locOriginal = $dirOriginal.$fyear.'/'.$falbum.'/'.$img; //get normal location of img $locSave = $dirLoad.$fyear.'_'.$falbum.'_'.$img; // location and how img will be save #TODO: maybe redefine algorith to use crop to add more pic quality list($originalW, $originalH) = getimagesize($locOriginal); $ratio = $originalW / $originalH; if($ratio > 1){ // landscape shape original photo $tgtH = $maxW/$ratio; $tgtW = $maxW; } else { // portrait shape Original photo $tgtW = $maxH*$ratio; $tgtH = $maxH; } //echo $originalW.'x'.$originalH.'@'.$ratio; #checking code behavior //echo '<br>'.$tgtW.'x'.$tgtH; #checking code behavior //get file extension explode replace eregi $ext = explode('.',$locOriginal); $ext = end($ext); //only variables should be passed by ref with end $ext = strtolower($ext); //turn it into lower case to match with switch below, just in case if(!file_exists($locOriginal)){ echo 'Error Found: File doesnt exist'; exit; } switch($ext){ //open the image according to file extension #note: must image we will work with are jpg/jpeg extension, added switch just in case case 'jpg': $imgOld = imagecreatefromjpeg($locOriginal); break; //no need but makes it look uniform case 'jpeg': $imgOld = imagecreatefromjpeg($locOriginal); break; case 'gif': $imgOld = imagecreatefromgif($locOriginal); break; case 'png': $imgOld = imagecreatefrompng($locOriginal); break; default: echo 'Error Found: Wrong File extension or file does not exist.'; break; //if doesnt match file extension } return $imgOld; echo 'is on'; ################################ //create a blank img with target dim. $imgNew = imagecreatetruecolor($tgtW, $tgtH); //resample old img with new imgNew size [0,0,0,0] crop options ImageCopyResampled($imgNew,$imgOld, 0, 0, 0, 0, $tgtW, $tgtH,$originalH, $originalH); switch($ext){ // case 'jpg': case 'jpeg': #Header("Content-type: image/jpeg"); Imagejpeg($imgNew,NULL,$quality); //set to null, to show picture in browser Imagejpeg($imgNew,$locSave,$quality); break; //added save location to save the file for future case 'gif': #Header("Content-type: image/gif"); Imagejpeg($imgNew,NULL,$quality); Imagegif($imgNew,$locSave,$quality); break; case 'png': #Header("Content-type: image/png"); Imagejpeg($imgNew,NULL,$quality); Imagepng($imgNew,$locSave,$quality); break; default: false; break; } ImageDestroy($imgOld); ImageDestroy($imgNew); ?>
  11. grasshopper31

    PHP image resize help!

    added Imagejpeg($imgNew,NULL,$quality); in all ext cases with the corresponding function according to file extension, to show the image in the broswer as well as saving it into the load folder. still no luck, but i think im one more step closer.
  12. grasshopper31

    PHP image resize help!

    I have two questions, what am I doing wrong? my script isnt working. It doesnt return errors nor a rezised pic. My second questions is just asking for ideas of how to improve this script in terms of security and quality. any help is appreciated. <?php #TODO: find ways to improve quality $quality = '100'; //in imagejpeg() type function default quality = 75, min = 0, max 100 $maxW = '180'; $maxH = '180'; $dirLoad = 'photos/load/'; //thumb size dir $dirOriginal = 'photos/'; //original size dir if(isset($_GET['a']) AND isset($_GET['y']) AND isset($_GET['i'])){ $falbum = stripslashes($_GET['a']); $fyear = stripslashes($_GET['y']); $img = stripslashes($_GET['i']); } else { echo 'lol'; exit; } $locOriginal = $dirOriginal.$fyear.'/'.$falbum.'/'.$img; //get normal location of img $locSave = $dirLoad.$fyear.'_'.$falbum.'_'.$img; // location and how img will be save #TODO: maybe redefine algorith to use crop to add more pic quality list($originalW, $originalH) = getimagesize($locOriginal); $ratio = $originalW / $originalH; if($ratio > 1){ // landscape shape original photo $tgtH = $maxW/$ratio; $tgtW = $maxW; } else { // portrait shape Original photo $tgtW = $maxH*$ratio; $tgtH = $maxH; } //echo $originalW.'x'.$originalH.'@'.$ratio; #checking code behavior //echo '<br>'.$tgtW.'x'.$tgtH; #checking code behavior //get file extension $ext = explode('.',$locOriginal); $ext = end($ext); //only variables should be passed by ref with end $ext = strtolower($ext); //turn it into lower case to match with switch below, just in case switch($ext){ //open the image according to file extension #note: must image we will work with are jpg/jpeg extension, added switch just in case #also bmt files are not supported by this script case 'jpg': //$imgOld = @imagecreatefromjpeg($locOriginal); break; no need but makes it look uniform case 'jpeg': $imgOld = @imagecreatefromjpeg($locOriginal); break; case 'gif': $imgOld = @imagecreatefromgif($locOriginal); break; case 'png': $imgOld = @imagecreatefrompng($locOriginal); break; default: $imgOld = false; break; } return $imgOld; //create a blank img with target dim. $imgNew = imagecreatetruecolor($tgtW, $tgtH); //resample old img with new imgNew size [0,0,0,0] crop options ImageCopyResampled($imgNew,$imgOld, 0, 0, 0, 0, $tgtW, $tgtH,$originalH, $originalH); switch($ext){ // #edit added header, forgot to #also bmt files are not supported by this script case 'jpg': case 'jpeg': Header("Content-type: image/jpeg"); Imagejpeg($imgNew,$locSave,$quality); break; case 'gif': Header("Content-type: image/gif"); Imagegif($imgNew,$locSave,$quality); break; case 'png': Header("Content-type: image/png"); Imagepng($imgNew,$locSave,$quality); break; default: false; break; } ImageDestroy($imgOld); ImageDestroy($imgNew); ?>
  13. grasshopper31

    Relative/Absolute paths Including Files

    Thank you! I actually tried dirname(__FILE__); but didn't work but it was just a missing "/" and some typos. It worked once i used the code in both pages where a file was being included.
  14. I have a file outside of the site root folder containing the password to connect to mysql that is being saved in a function, which is being included in my custom cms_class.php. Now my cms_class.php file is going to be included into a few other files including the main index.php file. Now we know when using relatives path is a big no no when including a file that has already included a file. So whats the successful way to do this. my directory looks something like this: /x/server/www <--- siteroot /x/server/www/cms/cms_class.php /x/server/www/index.php <-- main index a.k.a Home file /x/server/pass.php pass.php ---->includes into -->cms_class.php---->includes into --->index.php ---->includes into ---> (random files in different folders) im also including the pass.php file into phpmyadmin and other config files so i can change passwords from one file that is secured. (at least i think it is since its outsite of the siteroot folder) /x/server/apps/phpmyadmin/config.inc the reason for me doing this is just to protect the password to connect to my databases. If someone knows another way, better or not please let me know since im always interested in different methods when it comes to passwords protections, but i still want to know what will be the right way to include these files since i'm going to be doing something similar later with different files. Thanks in advance.
×

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.