lewis987 Posted October 14, 2008 Share Posted October 14, 2008 Im trying out oop (for a change) and so far so good. only problem is im getting this; Fatal error: Can't use function return value in write context in ........./sources/functions.php on line 18 Line 18 reads: if(empty(trim($VARS[$key]))){ the full code is posted below: <?PHP class Fld_Vwr{ var $epoch; var $lastSQLStatment = ""; var $lastError = ""; var $DBUser = ""; var $DBName = ""; var $DBHost = ""; var $DBPass = ""; var $DBPort = ""; var $DB = ""; function StartDL($VARS){ $requiredVars = array("file_name", "title"); foreach($requiredVars as $key) { if(empty(trim($VARS[$key]))){ { $fail = TRUE; } } //Explode the name at the slash: $exp = explode("/", $VARS['file_name']); $name = "downloads/".$exp[count($exp)-1]; if(!@copy($VARS['file_name'], $name) || $fail === TRUE){ return false }else{ header('Content-Description: File Transfer'); header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename='.urldecode($VARS['title']).".zip"); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($VARS['file_name'])); ob_clean(); flush(); readfile($name); ob_end_flush(); unlink($name); } } function hash_name($VAR2){ $epoch = time(); //Get PHP Version: $VER = phpversion(); $EXPLODE = explode(".", $VER); //Date stuff: $DATE_FORMATS = array("dmy","dny","jny","jmy","dmY","dnY","jnY","jmY"); $date_number = rand(0, (count($DATE_FORMATS)-1)); $date = date($DATE_FORMATS[$date_number]); //Time stuff: $real_time_formats = array("gis","His","Gis","his","gisu","Hisu","Gisu","hisu"); $real_time_number = rand(0,(count($real_time_formats) -1)); $real_time = date($real_time_formats[$real_time_number]); //Build String $STRING = str_shuffle($VAR2 . $Algos[$hash_number] . $date . $real_time . $this->epoch); $STRING = str_replace(",","", $STRING); $STRING = str_replace("_","", $STRING); $STRING = str_replace("+","", $STRING); $STRING = str_replace("-","", $STRING); $STRING = str_replace("(","", $STRING); $STRING = str_replace(")","", $STRING); if($EXPLODE[0] > "4"){ $hash = hash('whirlpool', $STRING); }else{ $hash = ""; while(strlen($hash) <= 96){ $hash .= md5(crc32(sha1(crc32(md5(sha1(md5(sha1($STRING))).md5(crc32(md5($STRING)))))))); } $hash = str_shuffle($hash); } return $hash; } function send_File($VARS){ $epoch = time(); $requiredVars = array("location", "file_types", "dir", "temp_dir", "get_var_1", "get_var_2", "get_var_3"); foreach($requiredVars as $key) { if(empty(trim($VARS[$key]))){ { return false; } } $epoch = $this->epoch; $folder = $LOCATION.urldecode($_GET[$VARS["get_var_1"]])."/".urldecode($_GET[$VARS["get_var_2"]])."/"; ///File ext/// $explode = explode(".",$_GET[$VARS["get_var_3"]]); $last = count($explode) - 1; $file_ext = strtolower($explode[$last]); if($VARS["file_types"][0] == "ANY"){ $ok = 1; }else{ //Check file ext: for($i = 0; $i < count($VARS["file_types"]); $i++){ if($file_ext == $VARS["file_types"][$i]){ $ok = 1; $i = 5000; }else{ $ok = 2; } } } if($ok == 2){ die("<div align=\"center\"><div class=\"error\"> Invalid file. <br />The file may exist, but the file extension is invalid. </div></div></body></html>"); } //Zip file name: $file = time().str_replace(" ","_",$_GET[$VARS["get_var_3"]]); $file = str_shuffle($file); //Add the extension on the zip folder. $zip_name = $dir.$file; $zip_name = str_replace("'","", $zip_name); $zip = new ZipArchive(); //Set the tempory file name: $tempFile = str_replace(" ","_",$_GET[$VARS["get_var_3"]]); $tempFile = $VARS["temp_dir"].$tempFile.$_SERVER['remote_addr'].$epoch; if(!@copy($folder.$_GET[$VARS["get_var_3"]], $tempFile)){ die("<div align=\"center\"><div class=\"error\"> Cannot copy file specified. <br />Please ensure it exists. </div></div></body></html>"); } if ($zip->open($zip_name.".zip", ZIPARCHIVE::OVERWRITE)!==TRUE) { exit("cannot create file.</body></html>"); } $zip->addFile($tempFile , $_GET[$VARS["get_var_3"]]); $zip->close(); unlink($TEMP); return $zip_name; } function send_Folder($VARS){ $epoch = time(); $requiredVars = array("location", "file_types", "dir", "temp_dir", "get_var_1", "get_var_2"); foreach($requiredVars as $key) { if(empty(trim($VARS[$key]))){ { return false; } } $epoch = $this->epoch; $folder = $LOCATION.urldecode($_POST[$GET_VAR_1])."/".urldecode($_POST[$GET_VAR_2])."/"; $open = opendir($folder); $i = 0; while(false !== ($file = readdir($open))){ if($file != "." || $file != ".."){ if($file_types[0] == "ANY"){ $files[$i] = $file; $i++; }else{ $EXPLODe = explode(".",$file); $last = count($EXPLODe) - 1; $file_ext = strtolower($EXPLODe[$last]); for($o = 0; $o < count($file_types); $o++){ if($file_ext == $file_types[$o] && is_dir($file) === FALSE){ $files[$i] = $file; $o = 100000; $i++; }else{ } } } } } //Create Zip Archive: //Create Zip Class Here: $zip = new ZipArchive(); //Make the Zip name here: $file = time().str_replace(" ","_", urldecode($_POST[$GET_VAR_2])); $file = str_shuffle($file); $file = str_replace("/","", $file); $zip_name = $dir.$file.".zip"; //Create the zip file: $res = $zip->open($zip_name, ZIPARCHIVE::OVERWRITE); if($res !== TRUE) { die("cannot open $zip_name. Ended with the error code: $res</body></html>"); } //Create loop to copy files to temp dir, add files and/or show error messages: for($i = 0; $i < count($files); $i++){ $FILE = str_replace(" ","_",$files[$i]); $TEMP = $temp_dir.$FILE.$_SERVER['remote_addr'].$epoch; if(!@copy($folder.$files[$i], $TEMP)){ echo("<div class=\"error\"> Cannot copy file specified. <br />Please ensure it exists and that it is the directory specified. </div>"); }else{ $zip->addFile($TEMP , $files[$i]); } } $zip->close(); //Remove all the files here: for($i = 0; $i < count($files); $i++){ $FILE = str_replace(" ","_",$files[$i]); $TEMP = $temp_dir.$FILE.$epoch; unlink($TEMP); } //Send the file name back to the script calling this file! return $zip_name; } function Clean_Dls(){ $time = time(); if(is_file("temp/REQ_time.txt") === TRUE){ $file_time = file_get_contents("temp/REQ_time.txt"); }else{ file_put_contents("temp/REQ_time.txt", $time); $file_time = $time; } //We need a limit for the file time, This can be changed, but we have set it to about a day. $limit = 60 * 60 * 24; if($file_time + $limit < $time){ //Try and open the downloads folder: $open = @opendir("downloads/"); while(FALSE !== ($file = readdir($open))){ if($file_time + $limit < filemtime("downloads/".$file)){ unlink("downloads/".$file); } } file_put_contents("temp/REQ_time.txt", $time); } } //Database stuff: function getError(){ print("Error!<br /> ".$this->lastError."<br />The SQL executed was: ".$this->lastSQLStatement); } function MyConnectOptions(){ $this->DBUser = "*************"; $this->DBPass = "***********"; $this->DBName = "*************"; $this->DBHost = "localhost"; $this->DBPort = ""; } function Connect(){ //Before we connect, We need to check the port variable to see if its set and is a number: if(ctype_digit($this->DBPort) === TRUE){ $this->DB = mysql_connect($this->DBHost.":".$this->DBPort, $this->DBUser, $this->DBPass) or die("MySQL Error:".mysql_error()); }else{ $this->DB = mysql_connect($this->DBHost, $this->DBUser, $this->DBPass) or die("MySQL Error:".mysql_error()); } mysql_select_db($this->DBName, $this->DB) or die("MySQL Error:".mysql_error()); } function Disconnect(){ mysql_close($this->DB) or die("MySQL Error:".mysql_error()); } function Insert($tbl){ //Sets all the variables: $cols = array(); $cols_use = array(); $values_use = array(); //We need to get ALL the columns from the table in $tbl; $pulledCols = mysql_query("SHOW COLUMNS FROM ".$tbl, $this->DB) or die("MySQL Error: ".mysql_error); while($columns = mysql_fetch_assoc($pulledCols)){ $cols[] = $columns['Field']; } foreach( $_POST as $key => $value){ if(in_array($key, $cols) && trim($value)){ if($value == "DATESTAMP"){ $value_use[] = "NOW()"; }else{ if(is_numeric($value) === TRUE){ $values_use[] = $value; }else{ $values_use[] = ( get_magic_quotes_gpc() ) ? "'".$value."'" : "'".addslashes($value)."'"; } $cols_use[] = "`".$key."`"; } } } if( (sizeof($cols_use) == 0 ) || (sizeof($values_use) == 0)){ $this->lastError = "Error: There was no data passed!"; return false; }else{ $SQL = "INSERT INTO `".$tbl."` (".implode(",",$cols_use). ") VALUES (".implode(",",$values_use). ")"; if( @mysql_query($SQL, $this->DB)){ return true; }else{ $this->lastError = "Error: ".mysql_error(); $this->lastSQLStatement = $SQL; return false; } } } function Select($tbl, $col, $data){ //Ensure all the data has been populated: if(empty($tbl) || empty($col) || empty($data)){ //Throw error: $this->lastError = "Error: No tables and/or columns set!"; return false; } //Secure the data: $tbl = ( get_magic_quotes_gpc() ) ? $tbl : addslashes($tbl); $col = ( get_magic_quotes_gpc() ) ? $col : addslashes($col); $data = ( get_magic_quotes_gpc() ) ? $data : addslashes($data); if(is_array($col) === TRUE){ if(is_array($data) === TRUE && count($col) == count($data)){ //Build up the SQL here: $SQL = "SELECT * FROM `".$tbl."` WHERE "; for($i = 0; $i < count($col); $i++){ $SQL .= "`".$col[$i]."` = '".$data[$i]."'"; if($i + 1 != count($col)){ $SQL .= " AND "; } } }else{ $this->lastError = "Error: Invalid data sent"; return false; } }else{ $SQL = "SELECT * FROM `".$tbl."` WHERE `".$col."` = '".$data."';"; } if($Q = @mysql_query($SQL, $this->DB)){ $this->lastSQLStatement = $SQL; return $Q; }else{ $this->lastError = "Error: ".mysql_error(); $this->lastSQLStatement = $SQL; return false; } } function Delete($tbl, $col, $data){ //Ensure all the data has been populated: if(empty($tbl) || empty($col) || empty($data)){ //Throw error: $this->lastError = "Error: No tables and/or columns set!"; return false; } //Secure the data: $tbl = ( get_magic_quotes_gpc() ) ? $tbl : addslashes($tbl); $col = ( get_magic_quotes_gpc() ) ? $col : addslashes($col); $data = ( get_magic_quotes_gpc() ) ? $data : addslashes($data); if(is_array($col) === TRUE){ if(is_array($data) === TRUE && count($col) == count($data)){ //Build up the SQL here: $SQL = "DELETE FROM `".$tbl."` WHERE "; for($i = 0; $i < count($col); $i++){ $SQL .= "`".$col[$i]."` = '".$data[$i]."'"; if($i + 1 != count($col)){ $SQL .= " AND "; } } }else{ $this->lastError = "Error: Invalid data sent"; return false; } }else{ $SQL = "DELETE FROM `".$tbl."` WHERE `".$col."` = '".$data."';"; } if($Q = @mysql_query($SQL, $this->DB)){ return $Q; }else{ $this->lastError = "Error: ".mysql_error(); return false; } $this->lastSQLStatement = $SQL; } function Update($tbl, $upd_col, $upd_data, $def_col, $def_data){ //Ensure all the data has been populated: if(empty($tbl) || empty($upd_col) || empty($upd_data) || empty($def_col) || empty($def_data)){ //Throw error: $this->lastError = "Error: one of the vars wasn't populated!"; return false; } //Secure the data: $tbl = ( get_magic_quotes_gpc() ) ? $tbl : addslashes($tbl); $upd_col = ( get_magic_quotes_gpc() ) ? $upd_col : addslashes($upd_col); $upd_data = ( get_magic_quotes_gpc() ) ? $upd_data : addslashes($upd_data); $def_col = ( get_magic_quotes_gpc() ) ? $def_col : addslashes($def_col); $def_data = ( get_magic_quotes_gpc() ) ? $def_data : addslashes($def_data); $SQL = "UPDATE `$tbl` SET "; if(is_array($upd_col) === TRUE && is_array($upd_data) === TRUE){ if(count($upd_col) == count($upd_data)){ for($i = 0; $i < count($upd_col); $i++){ if($upd_data == "DATESTAMP"){ $upd_data = "NOW()"; } $SQL .= "`".$upd_col[$i]."` = '".$upd_data."' "; if($i + 1 != count($upd_col)){ $SQL .= ", "; } } }else{ $this->lastError = "Error: Invalid data sent."; return false; } }elseif(!is_array($upd_col) && !is_array($upd_data)){ $SQL .= "`".$upd_col."` = '".$upd_data."'"; }else{ $this->lastError = "Error: Invalid data sent."; return false; } if(is_array($def_col) === TRUE){ if(is_array($def_data) === TRUE && count($col) == count($data)){ //Build up the SQL here: $SQL .= " WHERE "; for($i = 0; $i < count($col); $i++){ $SQL .= "`".$def_col[$i]."` = '".$def_data[$i]."'"; if($i + 1 != count($col)){ $SQL .= " AND "; } } }else{ $this->lastError = "Error: Invalid data sent"; return false; } }else{ $SQL .= " WHERE `".$col."` = '".$data."';"; } if($Q = @mysql_query($SQL, $this->DB)){ return true; }else{ $this->lastError = "Error: ".mysql_error(); return false; } $this->lastSQLStatement = $SQL; } } ?> Link to comment https://forums.phpfreaks.com/topic/128442-solved-stuck/ Share on other sites More sharing options...
lewis987 Posted October 14, 2008 Author Share Posted October 14, 2008 never mind, Trim was in the wrong place, Link to comment https://forums.phpfreaks.com/topic/128442-solved-stuck/#findComment-665586 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.