Jump to content

jkkenzie

Members
  • Posts

    412
  • Joined

  • Last visited

Everything posted by jkkenzie

  1. Hi: Am not sure if this is the best algorithm to go about saving a record and uploading (plus moving to another directory) files. I feel i need another algorithm? if (self::post()->isPost()) { #check if there is any file if($this->request->hasFiles() == true){ $uploads = $this->request->getUploadedFiles(); $isUploaded = false; #do a loop to handle each file individually foreach($uploads as $upload){ #define a "unique" name and a path to where our file must go $path = 'temp/'.md5(uniqid(rand(), true)).'-'.strtolower($upload->getname()); #move the file and simultaneously check if everything was ok if($upload->moveTo($path)) { #Build an array to be sent to the API for moving the uploaded file to front end directory $files=""; $files = array( 'name' => $upload->getName(), 'link' => $this->di['url']->get('temp/' . $upload->getName()), 'direction' => 'adverts' ); $saveResult = self::request()->request('move-advert/', array('file' => $files), 'POST'); if($saveResult->response == 'success') $isUploaded = true; else $isUploaded = false; } } #if any file couldn't be moved, then throw an message if($isUploaded) { $save_response = self::request()->request('advert/' . $id, self::editValues(self::post()->getPost()), 'POST'); if ($save_response->response == 'success') { $this->flashSession->success('Advert Updated'); return $this->response->redirect('adverts/list-adverts'); } else { $this->flashSession->notice('Could not update Advert'); } } else { $this->flashSession->notice('Some error ocurred. Please try again'); } }else { $this->flashSession->notice('You must Choose an advert image'); } } Any suggestions?
  2. trg: Sorry, i have to apologize that i forgot the enctype="multipart/form-data". I blame too many views (MVC). I did a lot of debugging though.... wasted a whole day, i was woken up early in the morning by the answer to my issue... :-)
  3. I am using phalcon framework and am trying to upload a file but hasFiles() returns nothing or false yet there are posted file. if($this->request->hasFiles() == true){ // echo "sdfsf"; exit(); ..... I cant go through that if statement.. Thanks in advance.
  4. Hi, I have an adverts table that has records of currently running adverts, i have not used stored procedures or triggers before. I would like to create a stored procedure or a trigger using phpmyadmin for mysql. Exactly what i want to achieve is, when a record is accessed in adverts table, it causes a table called HITS to create a record that has the adverts_id, IP where the advert was clicked from, current date. Is that possible?
  5. @ginerjm Thanks. found one error when i enabled error display. But still that error was not important. But your reply made me go back and checked i was using wrong variables all over. Now its working good. :-)
  6. I receive files/images and loop through an array as follows: $files=rearrfiles( $_FILES['image']); foreach($files as $key=>$item) { if(is_array($item) && !empty($item['name']) && !empty($item['tmp_name'])){ //$_POST['imageFile']=$item['name']; //echo $item['name']; if($error!=true && !uploadImageB(array('image'=>'image'), DB_EXTENTION."mod_projects_images", $naming, $search = $editId, $dir, 'photo')) { $error=true; $action='Edit'; $message.='<br>Images were unable to be uploaded.'; } } } The function uploadImageB() is as follows: function uploadImageB($info, $table, $naming, $search, $path, $add='uploaded', $maxw=1280, $maxh=1280, $dynamic=true, $id='Id', $thumbMaxWidth = 120) { global $connection; if(!$_POST){ global $HTTP_POST_VARS; @$_POST=$HTTP_POST_VARS;} if(!$_FILES){ global $HTTP_POST_FILES; @$_FILES=$HTTP_POST_FILES;} if(is_array($info) && !empty($info) && $table!='' && !empty($path)) { $error=false; $d=$naming; foreach($info as $key=>$val) { $names[$val]=$dynamic==true?$add.'_'.$result[$id].'_'.$d.'_.'.strtolower(mygetext($_FILES[$val]['name'])):$add.strtolower(mygetext($_FILES[$val]['name'])); if(is_array(@$_FILES[$val]) && !empty($_FILES[$val]['name']) && !empty($names[$val])) { if(!singMove($path, $names[$val], $_FILES[$val], array(), array('gif', 'jpeg', 'jpg', 'png', 'bmp', 'svg'))) { $error=true; break; } else{ $valid[$val]=$names[$val]; resizeImage($path.$names[$val], $maxw, $maxh); make_thumb($path.$names[$val],$names[$val], $path, $thumbMaxWidth); } } } if($error==true) return false; elseif(!empty($valid)) { $connection->info=$info; $connection->input=$valid; $connection->id=array('field'=>$id, 'val'=>addslashes($result[$id])); $connection->makenew($table); $connection->return_db($connection->query); } } return true; } I get the error: Images were unable to be uploaded. Any help?
  7. I cant believe it was just making the $_FILES an array: i dont know if this is right... array($_FILES['uploads']); if(myupload('../UserSiteFiles/'.rawurldecode($_POST['currentdir']), $_FILES['uploads'])){?> I just added... array($_FILES['uploads']); and it worked, file could be uploaded.
  8. Thanks: The only clue i have is magic_quotes_gpc when it on uploads work. No particular error at the moment.
  9. hi, i migrating an old CMS and there is something am not understanding: For some reason if magic_quotes_gpc is turned off, uploads dont work. Function below: function myupload($dir, $filein, $exclude=array(), $include=array(), $specs=array(), $det=array()) { if(is_array($filein)) { THIS IF RETURNS FALSE. I.E IT DOES NOT GO THROUGH HERE... IT JUMPS TO ELSE.. It seems the the $filein supplied to this function has a problem, though print_r show the value 1. $filein comes from the call below: myupload('../UserSiteFiles/'.rawurldecode($_POST['currentdir']), $_FILES['uploads']) WHAT happens to $_FILES and $_POST when magic_quotes_gpc=off ?? Thanks...
  10. I got it working by converting the last four functions to use mysqli as follows: <?php //creates database connectin returning true on success and false on failure function connect()//(v0.01) 27/05/06 { if($link = mysqli_connect($this->host, $this->login, $this->password, $this->database)) { $this->link=$link; return true;} else return false; } //Checks Whether the query qiven returns any results //returns false if it returns results true if no results are returned //if the query has an error it returns 'not determined' //It stores the number of results if false in the result property function dup_check($query)//(v0.01) 27/05/06 { //$database=$this->database; if($result=mysqli_query($this->link, $query)) { if($resultlen=mysqli_num_rows($result)) { if($resultlen>=1) return false; elseif($resultlen<1) return true; } else return true; } else return 'not determined'; } //Executes a query and returns the results in an array. //They are stored in the result property function return_db($select) { //$database=$this->database; if($result=mysqli_query($this->link, $select)) { if($confirm=@mysqli_num_rows($result)){ if($confirm>0){ $n=1; while($row=mysqli_fetch_array($result, MYSQLI_ASSOC)){ $return[$n]=$row; $n++; } mysqli_free_result($result);return $return;} else return 'no results'; } else{ $result ;return 'query exequted';} } else return false; } //closes the database connection function cl(){mysqli_close($this->link);} //select the last autoincrement function autoInc() { $result=mysqli_query($this->database, "SELECT LAST_INSERT_ID() AS `LAST_ID`", $this->link); if(!$result) return false; $result=mysqli_fetch_array($result, MYSQLI_ASSOC); if(!$result) return false; //var_dump($result); $this->auto=$result['LAST_ID']; return $result['LAST_ID']; } ?>
  11. The code is huge, sorry for posting the whole class: The only functions that am trying to use mysqli are the last four as below: <?php //creates database connectin returning true on success and false on failure function connect()//(v0.01) 27/05/06 { if($link = mysql_connect($this->host, $this->login, $this->password)) { $this->link=$link; return true;} else return false; } //Checks Whether the query qiven returns any results //returns false if it returns results true if no results are returned //if the query has an error it returns 'not determined' //It stores the number of results if false in the result property function dup_check($query)//(v0.01) 27/05/06 { $database=$this->database; if($result=mysql_db_query($database, $query, $this->link)) { if($resultlen=mysql_num_rows($result)) { if($resultlen>=1) return false; elseif($resultlen<1) return true; } else return true; } else return 'not determined'; } //Executes a query and returns the results in an array. //They are stored in the result property function return_db($select) { $database=$this->database; if($result=mysql_db_query($database, $select, $this->link)) { if($confirm=@mysql_num_rows($result)){ if($confirm>0){ $n=1; while($row=mysql_fetch_array($result, MYSQL_ASSOC)){ $return[$n]=$row; $n++; } mysql_free_result($result);return $return;} else return 'no results'; } else{ $result ;return 'query exequted';} } else return false; } //closes the database connection function cl(){mysql_close($this->link);} //select the last autoincrement function autoInc() { $result=mysql_db_query($this->database, "SELECT LAST_INSERT_ID() AS `LAST_ID`", $this->link); if(!$result) return false; $result=mysql_fetch_array($result, MYSQL_ASSOC); if(!$result) return false; //var_dump($result); $this->auto=$result['LAST_ID']; return $result['LAST_ID']; } ?>
  12. Hi, I need help converting this class to use mysqli instead of using the deprecated functions like mysql_db_query e.t.c. I tried a couple of time but ended up with alot of errors..... Here is the class: <?php //This file contains depreceated methods and a complete revision is to be done //This class builds three kinds of queries. INSERT, SELECT, DELETE, and UPDATE class q_build { var $input, //This is an array of the input data for the UPDATE and INSERT queries. $info, //This is an array of the keys to be used for all the queries. $query, //This is where the output query is stored. $table, //The table to be queried. $id, //A store for the primary field or the key to be used in the query. $countRow, $auto, $funcs, $extras; //A for aditional information currently used to store callback functions for data to be processed before it is inserted. //////////////////////////////////////////////////////////////////////// // // // insert_q() // // This Method builds an insert query. It only requires: // // 1. Fields to be affected, stored in the info property // // 2. Data, stored in the input property // // 3. Callback functions(Optional), stored in the // // extras property // // // //////////////////////////////////////////////////////////////////////// function insert_q($table='') { $info=$this->info; $fields=''; $values=''; $input=$this->input; $d=0; if(is_array($info) && is_array($input)){ foreach($info as $key=>$val) { if($d==2) $coma=','; else $coma=''; $fields.=$coma.'`'.$key.'`'; if(isset($this->extras[$key]) && function_exists($this->extras[$key])) { $nval=call_user_func($this->extras[$key], @$input[$val]); $values.=$coma."'".$nval."'"; } else $values.=$coma."'".@$input[$val]."'"; $d=2; } $this->query='INSERT INTO `'.(!empty($table)?$table:$this->table).'`('.$fields.')'."\n"; $this->query.='VALUES('.$values.');'."\n"; return true;} else{ $this->query='' ;return false;} } //////////////////////////////////////////////////////////////////////// // // // update_q() // // This Method builds an update query. It only requires: // // 1. Fields to be affected, stored in the info property // // 2. Data, stored in the input property // // 3. Callback functions(Optional), stored in the // // extras property // // // //////////////////////////////////////////////////////////////////////// function update_q($table='') { $info=$this->info; $sq=''; $input=$this->input; $d=0; if(is_array($info) && is_array($input) && !empty($this->id['field']) && (!empty($this->id['val']) || @$this->id['val']=='0')){ foreach($info as $key=>$val) { if($d==2) $coma=','; else $coma=''; if(isset($this->extras[$key]) && function_exists($this->extras[$key])) $nval=call_user_func($this->extras[$key], @$input[$val]); elseif(isset($input[$val])) $nval=$input[$val]; else $nval=false; if($nval!==false) $sq.=$coma.'`'.$key."`='".$nval."' "; $d=2; } $cndVar=(isset($this->id['state']))?"`".$this->id['field']."`".$this->id['state']['b4'].$this->id['val'].$this->id['state']['aft']:"`".$this->id['field']."` ='".$this->id['val']."'"; $this->query="UPDATE `".(!empty($table)?$table:$this->table)."` SET ".$sq."WHERE $cndVar;\n"; unset($this->id['val'], $this->id['field']); return true;} else{ unset($this->id['val'], $this->id['field']) ;$this->query='' ;return false;} } ////////////////////////////////////////////////////////////////////////////////////////////////// // // // select_q($start, $length, $all, $cnd, $cndv, $addtx, $conc, $scount // // This Method builds an select query. It only requires: // // // ////////////////////////////////////////////////////////////////////////////////////////////////// function select_q ( $start=0, // The start position of the results i.e from first result(integer) $length='', //The length of the data to be selected(integer) $all=false, //Whether to selectt all fields or only those in the info property(bool) $cnd=false, //Whether to make a condition for the query(bool) $cndv=array(), //The array used to make the condition(array) $addtx='', //Text to be added before the end of the query(string) $conc=false, //Whether the added text requires an and or not(bool) $scount=false , //Whether to select count as `rows` or not $orderby=array(), // $myCount='count', //Store The count query; $table='' // ) { $funcs=$this->funcs; $info=$this->info; $this->funcs=NULL; if(is_array($info) && $all==false){ $d=0; $fields=''; $coma=''; foreach($info as $key=>$val) { $distinct=($val=='dist')?'DISTINCT':''; if(!empty($funcs[$key])){ if(is_array($funcs[$key])){ foreach($funcs[$key] as $func) { $fields.="{$coma}{$distinct} {$func}( `{$key}` ) AS `{$key}_{$func}`"; $coma=','; $distinct=""; } } else $fields.="{$coma}{$distinct} {$funcs[$key]}( `{$key}` ) AS `{$key}`"; } else $fields.=$coma.' '.$distinct.' `'.$key.'`'; $coma=','; }} else $fields='*'; $and=''; if(is_array($cndv) && $cnd==true){ $d=0; $condition=''; foreach($cndv as $sval) { $and=($d==2)?(isset($sval['or'])?' OR ':' AND '):''; $opBrac=(isset($sval['opB'])?'( ':''); $clBrac=(isset($sval['clB'])?' )':''); if(!isset($sval['state']) && isset($sval['name'], $sval['val'])) { $condition.=$and.$opBrac.(!empty($sval['func'])?$sval['func'].'(':'').'`'.$sval['name']."`".(!empty($sval['func'])?')':'')."='".$sval['val']."'".$clBrac; $d=2;} elseif(isset($sval['state'], $sval['val']) && is_array($sval['state'])) { $condition.=$and.$opBrac.'`'.$sval['name'].'`'.@$sval['state']['b4'].$sval['val'].@$sval['state']['aft'].$clBrac; $d=2; } }} else $condition='1'; $chk=trim($condition); empty($chk)?$saver=' 1 ':$saver=''; (empty($addtx) || empty($condition) || !$conc)?$and='':$and=' AND '; settype($start, 'integer'); settype($length, 'integer'); if(empty($length) || $length==0) $limit=''; else $limit=' LIMIT '.$start.', '.$length; if($orderby=='RAND()'){$orderStr=' ORDER BY RAND()'; $limit=$orderStr.' LIMIT '.$length; } if(is_array($orderby)){ $orderStr=''; foreach($orderby as $order){ if(!empty($order['field']) && !empty($order['order'])){ if(empty($orderStr)){ $orderStr=" ORDER BY `".$order['field']."` ".$order['order'];} else $orderStr.=", `".$order['field']."` ".$order['order'];}} $limit=$orderStr.$limit;} $coStr=$myCount=='max'?'MAX':($myCount=='min'?'MIN':($myCount=='sum'?'SUM':'COUNT')); if($scount==true) $this->myCount="SELECT $coStr( ".(!empty($this->countRow)?'`'.$this->countRow.'`':'*')." ) AS `rows` FROM `".(!empty($table)?$table:$this->table).'` WHERE '.$saver.$condition.$and.$addtx.';'; $this->query='SELECT '.$fields.' FROM `'.(!empty($table)?$table:$this->table).'` WHERE '.$saver.$condition.$and.$addtx.$limit; return true; } ////////////////////////////////////////////////////////////////////////////////////////////////// // // // delete_q($start, $length, $all, $cnd, $cndv, $addtx, $conc, $scount) // // This Method builds a delete query. It only requires: // // // ////////////////////////////////////////////////////////////////////////////////////////////////// function delete_q ( $cndv=array(), //The array used to make the condition(array) $addtx='', //Text to be added before the end of the query(string) $conc=false, //Whether the added text requires an and or not(bool), $table='' //the table being used ) { $and=''; if(is_array($cndv)){ $d=0; $condition=''; foreach($cndv as $sval) { $and=($d==2)?(isset($sval['or'])?'OR':'AND'):''; $opBrac=(isset($sval['opB'])?'( ':''); $clBrac=(isset($sval['clB'])?' )':''); if(!isset($sval['state']) && isset($sval['name'], $sval['val'])) { $condition.=$and.$opBrac.'`'.$sval['name']."`='".$sval['val']."'".$clBrac; $d=2;} elseif(isset($sval['state'], $sval['val']) && is_array($sval['state'])) { $condition.=$and.$opBrac.'`'.$sval['name'].'`'.@$sval['state']['b4'].$sval['val'].@$sval['state']['aft'].$clBrac; $d=2; } }} else $condition='1'; $chk=trim($condition); empty($chk)?$saver=' 1 ':$saver=''; (empty($addtx) || empty($condition) || !$conc)?$and='':$and=' AND '; $this->query='DELETE FROM `'.(!empty($table)?$table:$this->table).'` WHERE '.$saver.$condition.$and.$addtx; return true; } } //This class adds a database connection and query execution functions to the q_build class class DbQuery extends q_build { var $result, //Store the result of a query $link, //Stores the database connection link $password, //Input the user password $host, //Input the database host name $database, //Input the database name $login; //Input the user login //creates database connectin returning true on success and false on failure function connect() { if($link = mysql_connect($this->host, $this->login, $this->password)) { $this->link=$link; return true;} else return false; } //Checks Whether the query qiven returns any results //returns false if it returns results true if no results are returned //if the query has an error it returns 'not determined' //It stores the number of results if false in the result property function dup_check($query) { $database=$this->database; if($result=mysql_db_query($database, $query, $this->link)) { if($resultlen=mysql_num_rows($result)) { if($resultlen>=1) return false; elseif($resultlen<1) return true; } else return true; } else return 'not determined'; } //Executes a query and returns the results in an array. //They are stored in the result property function return_db($select) { $database=$this->database; if($result=mysql_db_query($database, $select, $this->link)) { if($confirm=@mysql_num_rows($result)){ if($confirm>0){ $n=1; while($row=mysql_fetch_array($result, MYSQL_ASSOC)){ $return[$n]=$row; $n++; } mysql_free_result($result);return $return;} else return 'no results'; } else{ $result ;return 'query exequted';} } else return false; } //closes the database connection function cl(){mysql_close($this->link);} //select the last autoincrement function autoInc() { $result=mysql_db_query($this->database, "SELECT LAST_INSERT_ID() AS `LAST_ID`", $this->link); if(!$result) return false; $result=mysql_fetch_array($result, MYSQL_ASSOC); if(!$result) return false; //var_dump($result); $this->auto=$result['LAST_ID']; return $result['LAST_ID']; } } ?>
  13. Still that example doesn't work when category_id and period_id are different values for one entry. I think i should focus normalizing the tables.
  14. Ok. thanks. That means when entries are entered in mod_music_entries, i include script to add to the extra tables you have suggested. Well, its a long shot , check this out http://sqlfiddle.com/#!2/f1361/1/0
  15. I have the followimng tables: CREATE TABLE IF NOT EXISTS `mod_music_periods` ( `id` int(1) NOT NULL AUTO_INCREMENT, `the_in` varchar(4) NOT NULL, `period` varchar(4) NOT NULL, `priority` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `period` (`period`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ; CREATE TABLE IF NOT EXISTS `mod_music_category` ( `id` int(11) NOT NULL AUTO_INCREMENT, `category` varchar(250) NOT NULL, `teaser` text, `priority` int(11) NOT NULL DEFAULT '0', `style` varchar(25) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; CREATE TABLE IF NOT EXISTS `mod_music_entries` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` text COLLATE latin1_general_ci, `teaser` text COLLATE latin1_general_ci, `description` text COLLATE latin1_general_ci, `song_yr` varchar(4) COLLATE latin1_general_ci DEFAULT NULL, `song_name` varchar(250) COLLATE latin1_general_ci DEFAULT NULL, `photo` text COLLATE latin1_general_ci, `active` enum('1','0') COLLATE latin1_general_ci NOT NULL DEFAULT '0', `priority` int(5) DEFAULT NULL, `period_id` char(150) COLLATE latin1_general_ci DEFAULT NULL, `category_id` char(150) COLLATE latin1_general_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=21 ; 1. When saving to mod_music_entries we allow an entry/record to have more than one "period_id" and "category_id". 2. A "mod_music_entries.period_id" field uses the mod_music_periods.id field enclosed in "b" and "e" characters plus a "/n". e.g. b1e /n b2e/n b3e/n .. e.t.c 3. A "mod_music_entries.category_id" field uses the mod_music_category.id field enclosed in "b" and "e" characters plus a "/n". e.g. b1e /n b2e/n b3e/n .. e.t.c I need to select mod_music_entries records but group first in mod_music_category.category then for each group of the later as a subgroup i need to group in mod_music_periods.period. somthing like: //Write Category one only if it has something in mod_music_entries.category_id 1. mod_music_category.category //Write this period only if there is something in mod_music_entries.period_id a) mod_music_periods.period i) mod_music_entries.name ii) mod_music_entries.name b)mod_music_periods.period i) mod_music_entries.name ii) mod_music_entries.name //Write Category two only if it has something in mod_music_entries.category_id 2. mod_music_category.category //Write this period only if there is something in mod_music_entries.period_id a) mod_music_periods.period i) mod_music_entries.name ii) mod_music_entries.name b)mod_music_periods.period i) mod_music_entries.name ii) mod_music_entries.name
  16. I have two tables, mod_music_category has a field id which autoincrements and the other table, mod_music_entries has category_id field whose value is mod_music_category.id but enclosed with "b" and "e" .e.g."b mod_music_category.id e" no spaces like b1e. I am trying to select all records from mod_music_entries whose category_id is LIKE or EQUAL to mod_music_category id field as follows: SELECT `c`.id, `c`.category, `e`.`category_id`, `c`.teaser, `c`.style FROM `".DB_EXTENTION."mod_music_category` `c` LEFT JOIN `".DB_EXTENTION."mod_music_entries` `e` ON( `e`.`category_id` = '%b`c`.`id`e%') ORDER BY c.`priority` ; Its returning all values even if there is no join. Is ther a better way. Thanks
  17. Hi! I have changed the script all together: Am able to download the file outside root directory BUT iam not able to play it. The script below: i have disabled the "Content Disposition" so that it does not force download. but nothing happens. the player keeps rotating without an error: define('ALLOWED_REFERRER', ''); // Download folder, i.e. folder where you keep all files for download. // MUST end with slash (i.e. "/" ) //define('BASE_DIR','/home/user/downloads/'); define('BASE_DIR',$_SERVER['DOCUMENT_ROOT'].'/../privatelogged/'); // log downloads? true/false define('LOG_DOWNLOADS',true); // log file name define('LOG_FILE','downloads.log'); // Allowed extensions list in format 'extension' => 'mime type' // If myme type is set to empty string then script will try to detect mime type // itself, which would only work if you have Mimetype or Fileinfo extensions // installed on server. $allowed_ext = array ( // archives 'zip' => 'application/zip', // documents 'pdf' => 'application/pdf', 'doc' => 'application/msword', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', // executables 'exe' => 'application/octet-stream', // images 'gif' => 'image/gif', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', // audio 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav', // video 'mp4' => 'video/mp4', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'mov' => 'video/quicktime', 'avi' => 'video/x-msvideo' ); #################################################################### ### DO NOT CHANGE BELOW #################################################################### // If hotlinking not allowed then make hackers think there are some server problems if (ALLOWED_REFERRER !== '' && (!isset($_SERVER['HTTP_REFERER']) || strpos(strtoupper($_SERVER['HTTP_REFERER']),strtoupper(ALLOWED_REFERRER)) === false) ) { die("Internal server error. Please contact system administrator."); } // Make sure program execution doesn't time out // Set maximum script execution time in seconds (0 means no limit) set_time_limit(0); if (!isset($_GET['video']) || empty($_GET['video'])) { die("Please specify file name for download."); } // Nullbyte hack fix if (strpos($_GET['video'], "\0") !== FALSE) die(''); // Get real file name. // Remove any path info to avoid hacking by adding relative path, etc. $fname = basename($_GET['video']); $fname="K@1~@".$fname; // Check if the file exists // Check in subfolders too function find_file ($dirname, $fname, &$file_path) { $dir = opendir($dirname); while ($file = readdir($dir)) { if (empty($file_path) && $file != '.' && $file != '..') { if (is_dir($dirname.'/'.$file)) { find_file($dirname.'/'.$file, $fname, $file_path); } else { if (file_exists($dirname.'/'.$fname)) { $file_path = $dirname.'/'.$fname; return; } } } } } // find_file // get full file path (including subfolders) $file_path = ''; find_file(BASE_DIR, $fname, $file_path); if (!is_file($file_path)) { die("File does not exist. Make sure you specified correct file name."); } // file size in bytes $fsize = filesize($file_path); // file extension $fext = strtolower(substr(strrchr($fname,"."),1)); // check if allowed extension if (!array_key_exists($fext, $allowed_ext)) { die("Not allowed file type."); } // get mime type if ($allowed_ext[$fext] == '') { $mtype = ''; // mime type is not set, get from server settings if (function_exists('mime_content_type')) { $mtype = mime_content_type($file_path); } else if (function_exists('finfo_file')) { $finfo = finfo_open(FILEINFO_MIME); // return mime type $mtype = finfo_file($finfo, $file_path); finfo_close($finfo); } if ($mtype == '') { $mtype = "application/force-download"; } } else { // get mime type defined by admin $mtype = $allowed_ext[$fext]; } // Browser will try to save file with this filename, regardless original filename. // You can override it if needed. if (!isset($_GET['fc']) || empty($_GET['fc'])) { $asfname = $fname; } else { // remove some bad chars $asfname = str_replace(array('"',"'",'\\','/'), '', $_GET['fc']); if ($asfname === '') $asfname = 'NoName'; } // set headers header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Type: $mtype"); //header("Content-Disposition: attachment; filename=\"$asfname\""); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . $fsize); // download // @readfile($file_path); $file = @fopen($file_path,"rb"); if ($file) { while(!feof($file)) { print(fread($file, 1024*); flush(); if (connection_status()!=0) { @fclose($file); die(); } } @fclose($file); } // log downloads if (!LOG_DOWNLOADS) die(); $f = @fopen(LOG_FILE, 'a+'); if ($f) { @fputs($f, date("m.d.Y g:ia")." ".$_SERVER['REMOTE_ADDR']." ".$fname."\n"); @fclose($f); } If i disable the "Content-Length" and "Content-Type" i get very many characters and symbols %$&%^&%^&%^&%^ on screen... Thanks for your responses...
  18. Hi! I have tried to add this link to the player under file:"sales/getfFile.... But it its saying bad source. When this code pasted on the address bar , i can download the file..... But the player cannot. $VideoF= stripslashes($_GET['download_file']); $VideoIm = preg_replace('/\.[^.]+$/','',$VideoF); if(isUserLoggedIn()) { ?> <script type="text/javascript" src="jwplayer/jwplayer.js"></script> <script type="text/javascript" src="jwplayer/jwplayer.html5.js"></script> <div id="myElement">Loading the player...</div> <script type="text/javascript"> jwplayer("myElement").setup({ file: "sales/getfFile.php?download_file=<?php echo $VideoF; ?>", image: "sales/assets/img/history/<?php echo $VideoIm; ?>.jpg" }); </script> <?php } ?> the download script is : $path_parts = pathinfo($_GET['download_file']); $file_name = $path_parts['basename']; $fullPath = "../privatefolder/".$file_name; if ($fd = fopen ($fullPath, "r")) { $fsize = filesize($fullPath); $path_parts = pathinfo($fullPath); $ext = strtolower($path_parts["extension"]); switch ($ext) { case "pdf": header("Content-type: application/pdf"); // add here more headers for diff. extensions header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download break; case "mp4": header("Content-type: video/mp4"); // add here more headers for diff. extensions header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download break; default: header("Content-type: application/octet-stream"); header("Content-Disposition: filename=\"".$path_parts["basename"]."\""); } header("Content-length: $fsize"); header("Cache-control: private"); //use this to open files directly while(!feof($fd)) { $buffer = fread($fd, 2048); echo $buffer; } } fclose ($fd); exit; Do you guys have netter way of playing videos outside root directory?
  19. I got the arrays by using print_r() but the values come from the database. I did get the page name by exploding url from $SERVER... and got the text before the .(dot) somthing e.g. services.htm the page name = "services" then i use that to access its ID from the Database and get its parent (infact am using a single mysql query to do that) BUT there are pages that load from modules and not from pages table.... these are pages generated during runtime.... am yet to figure out how to fix that. thanks!
  20. class RecursiveArrayOnlyIterator extends RecursiveArrayIterator { public function hasChildren() { return is_array($this->current()); } } $iterator = new RecursiveArrayIterator($chItems); iterator_apply($iterator, 'traverseStructure', array($iterator)); function traverseStructure($iterator) { while ( $iterator -> valid() ) { if ( $iterator -> hasChildren() ) { // print all children foreach ($iterator->getChildren() as $key => $value) { echo $iterator->key(). ', '.$key . ', ' . $value ; } traverseStructure($iterator -> getChildren()); } else { //echo $iterator -> key() . ' : ' . $iterator -> current() .PHP_EOL; } $iterator -> next(); } } I have tried this but i cant match the $value with a GET variable and also get its descendant's keys..
  21. I have the following arrays: //$this->links is an array with the following Array ( [-1] => Array ( [text] => Home [url] => pages/HOME.htm ) [1] => Array ( [text] => About us [url] => pages/About_us.htm ) [2] => Array ( [text] => Services [url] => pages/Services.htm ) [3] => Array ( [text] => Portfolio [url] => pages/Portfolio.htm ) [4] => Array ( [text] => FAQs [url] => pages/FAQs.htm ) [5] => Array ( [text] => Contact Us [url] => pages/Contact_Us.htm ) ) //$this->PrItems is an array with the following Array ( [1] => 886_P [2] => 962_P ) //$this->chiItems is an array with the following Array ( [1] => Array ( [886_P] => Array ( [959_P] => Array ( [text] => Overview [url] => pages/Overview.htm ) [960_P] => Array ( [text] => Directors [url] => pages/Directors.htm ) [961_P] => Array ( [text] => Representatives [url] => pages/Representatives.htm ) ) ) [2] => Array ( [962_P] => Array ( [965_P] => Array ( [text] => Custom Designed Homes [url] => pages/Custom_Designed_Homes.htm ) [966_P] => Array ( [text] => Pre-Designed Homes [url] => pages/Pre-Designed_Homes.htm ) [967_P] => Array ( [text] => Ready to Occupy [url] => pages/Ready_to_Occupy.htm ) ) ) ) To get to [text] => Directors i get backwards as follows: [960_P] then [886_P] then [1] in $this->PrItems THEN match [1] (parent above ) with [1] in $this->links to get [text] => About us I wanted to achieve a result like (using above): About Us .:. Directors Like a Breadcrumb What i have tried is: foreach($this->links as $Lnkkey=>$val) { if(strtolower($val['text']) == $page) { //$ParentId=$Lnkkey; echo '<li class="active"><a href="#" onclick="return false;" >'.@$val['text'].'</a></li>'; } else { $breadcrumb='<li class="active"><a href="#" onclick="return false;" >'.@$val['text'].'</a></li>'; $parentkey = find_parent($this->chItems, $page); echo $parentkey; } } function find_parent($array, $needle, $parent = null) { foreach ($array as $key => $value) { if (is_array($value)) { $pass = $parent; if (is_string($key)) { $pass = $key; } $found = find_parent($value, $needle, $pass); if ($found !== false) { return $found; } } else if ($key === 'text' && $value === $needle) { return $parent; } } return false; } thanks in advance
  22. Hi, Good stuff! thanks, the second one works: Look at the final query: SELECT expense_entries2.progid, expense_entries2.actid, expense_entries2.itemid, expense_entries2.subitemid, expense_entries2.subitemcatid,expense_entries2.expenseid, SUM(approvals.approved) as approved, expense_entries2.TotalEpense, (SUM(approvals.approved)-expense_entries2.TotalEpense) as Difference, expense_entries2.YearOfApprovalAndUse FROM (SELECT expense_entries.progid, expense_entries.actid, expense_entries.itemid, expense_entries.subitemid, expense_entries.subitemcatid,expense_entries.expenseid, SUM(expense_entries.amount) as TotalEpense, YEAR(expense_entries.transDate) as YearOfApprovalAndUse FROM expense_entries GROUP BY progid, actid, itemid, subitemid, subitemcatid, expenseid, YearOfApprovalAndUse) as expense_entries2 JOIN approvals ON expense_entries2.progid = approvals.progid AND expense_entries2.actid = approvals.actid AND expense_entries2.itemid = approvals.itemid AND expense_entries2.subitemid = approvals.subitemid AND expense_entries2.subitemcatid = approvals.subitemcatid AND expense_entries2.expenseid = approvals.expenseid AND expense_entries2.YearOfApprovalAndUse = approvals.budget_year GROUP BY expense_entries2.progid, expense_entries2.actid, expense_entries2.itemid, expense_entries2.subitemid, expense_entries2.subitemcatid,expense_entries2.expenseid, expense_entries2.YearOfApprovalAndUse - progid comes from Programs table - how do we include a query here to select the ProgramName from Programs table: - same to actid => activity table
  23. Hi! i have two tables: Table "a" has the following records: | program | Activity | expense | transDate --------------------------------------------------------- 1 | 1 | 2000 | yyyy/mm/dd H:m:s 2 | 3 | 234 | yyyy/mm/dd H:m:s 1 | 1 | 234 | yyyy/mm/dd H:m:s 2 | 3 | 234 | yyyy/mm/dd H:m:s Table "b" has the following records | program | Activity | approved| approveDate --------------------------------------------------------- 1 | 1 | 3000 | yyyy/mm/dd H:m:s 2 | 3 | 5034 | yyyy/mm/dd H:m:s 6 | 1 | 1234 | yyyy/mm/dd H:m:s 4 | 2 | 2304 | yyyy/mm/dd H:m:s what i want to achieve is : Select all records in table "a" and group them so that a group has same "program" and "Activity" number and of the same YEAR THEN sum the expense for each group . the sum found is then subtracted from the Table "b" Approved amount WHERE "Program" and "Activity" in both tables are the same. results: | program | Activity | approved| TotalEpense | Difference | YearOfApprovalAndUse ------------------------------------------------------------------------------------------------------ 1 | 1 | 3000 | 2234 | 766 | yyyy (we indicate the year extracted from the transaction date) 2 | 3 | 5034 | 468 | 4566 | yyyy (we indicate the year extracted from the transaction date) How is it possible through a mysql query? thanks in advance.
×
×
  • 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.