Jump to content

jkkenzie

Members
  • Posts

    412
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

jkkenzie's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

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