Jump to content

lewis987

Members
  • Posts

    214
  • Joined

  • Last visited

    Never

About lewis987

  • Birthday 04/19/1990

Contact Methods

  • MSN
    scoop_987@vista.aero

Profile Information

  • Gender
    Male
  • Location
    Fife - Scotland

lewis987's Achievements

Member

Member (2/5)

0

Reputation

  1. never mind, Trim was in the wrong place,
  2. 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; } } ?>
  3. I was thinking something like this: $requiredVars = array("location", "file_types", "dir", "temp_dir", "get_var_1", "get_var_2", "get_var_3"); $arrayCount = count($requiredVars); for($i = 0; $i < $arrayCount; $i++){ if(empty(trim($VAR[$requiredVars[$i]]))){ return false; } } It has the same effect...
  4. Im trying to optimize some code i've written up, the thing is, i need to check if an array that is sent to a function has the right keys set. At the minute im using an if elseif statement and it looks ugly. Im wondering if its faster and more practical settings a numbered array with the names of keys that are required and checking it in a loop. Is that more practical?
  5. I dont totally understand you, BUT, you can try this: $DB = new DB; #Change DB to the class that the function is contained in; $name = "blah"; $result = $DB->getMemberAndLocationByName($name); print_r($result); //You can use a loop instead of printing everything out in a oner. I think thats your question solved;
  6. Im trying to make a download site that always zips files, I can get the part for individual files to work flawlessly. The problem is (im using a music folder as an example) that when the user clicks the "download album" button. The function below creates the username and is meant to open or create (dependant if the file exists). The error is that its not creating the file at all. But the same code for the individual file works. Im confused, both functions are below so you can see what each function does. *NOTE* send_File is MEANT to use $_GET and send_Folder is meant to use $_POST; $folder returns what I want it to; send_File(): function send_File(){ global $LOCATION; global $file_types; global $dir; global $temp_dir; global $GET_VAR_3; global $GET_VAR_2; global $GET_VAR_1; global $epoch; $folder = $LOCATION.urldecode($_GET[$GET_VAR_1])."/".urldecode($_GET[$GET_VAR_2])."/"; ///File ext/// $EXPLODe = explode(".",$_GET[$GET_VAR_3]); $last = count($EXPLODe) - 1; $file_ext = strtolower($EXPLODe[$last]); if($file_type[0] == "ANY"){ $ok = 1; }else{ //Check file ext: for($i = 0; $i < count($file_types); $i++){ if($file_ext == $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().urldecode($_GET[$GET_VAR_3]); $file = str_shuffle($file); //Add the extension on the zip folder. Remove ' from the name $zip_name = $dir.$file; $zip_name = str_replace("'","", $zip_name); $zip = new ZipArchive(); //Set the tempory file name: $FILE = str_replace(" ","_",$_GET[$GET_VAR_3]); $TEMP = $temp_dir.$FILE.$_SERVER['remote_addr'].$epoch; if(!@copy($folder.$_GET[$GET_VAR_3], $TEMP)){ die("<div align=\"center\"><div class=\"error\"> Cannot copy file specified. <br />Please ensure it exists and that it is the directory specified. </div></div></body></html>"); } if ($zip->open($zip_name.".zip", ZIPARCHIVE::CREATE)!==TRUE) { exit("cannot create file.</body></html>"); } $zip->addFile($TEMP , $_GET[$GET_VAR_3]); $zip->close(); unlink($TEMP); return $zip_name; } send_Folder(): function send_Folder(){ global $LOCATION; global $file_types; global $dir; global $temp_dir; global $GET_VAR_2; global $GET_VAR_1; global $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); $zip_name = $dir.$file.".zip"; //Create the zip file: if ($zip->open($zip_name, ZipArchive::CREATE) !== TRUE) { die("cannot open $zip_name.</body></html>"); } //Create loop to 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 align=\"center\"><div class=\"error\"> Cannot copy file specified. <br />Please ensure it exists and that it is the directory specified. </div></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; } Any help or code optimization is appreciated.
  7. yea... i uploaded the wrong copies... but they will remain until i finish making some extra features...
  8. it should... i dont see why i wont..t... what about if you press enter??
  9. just to let ya know... yea i see them both...
  10. //Edit: ok... i never realised that with AJAX you have to make a new var per xmlrequest thing... so now it should all work, the shouts seem to work 100% here, with enter AND with the shout button. So now everything *should* work without a problem Post any errors here *Note: I know that the "Invite user" on your own chat room doesnt work, thats my next task!
  11. sorry unidox, forgot to edit it again.. and as for FF not posting... i dont know where the problem is... i can get it to post shouts when im on 127.0.0.1 (localhost)
  12. aight... got it to work in IE, FF, and opera with both pressing enter AND pressing the button Safari is the exception... the enter button way doesnt work... but i dont care at this present moment! uploading new files now!
  13. Fiddlesticks (dont wanna swear) but ive been using $_POST in the data.php file instead of $HTTP_RAW_POST_DATA... so damned cheesed off... haha
  14. Cookies are to keep the user logged in if they close the browser and sessions are used to keep the user logged in until they close their session or they have been inactive for more than 15 minutes (i think)
×
×
  • 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.