
GreenSmurf
Members-
Posts
108 -
Joined
-
Last visited
Everything posted by GreenSmurf
-
You are right about PHP doing the calculation in UNIX_TIMESTAMP but at least it is not in the DB for now and I just need to find a better solution to avoid the UNIX_TIMESTAMP.
-
Got it. Its messy but the functionality is there: if ($reQuest!=""){ $timeSub = date("h:i A", strtotime('+1 day +1 minute '.$reQuest)); $timeNow = date("Y-m-d H:i:s", time()); $timeNow = strtotime($timeNow); //echo $timeNow."<br />"; //echo $reQuest."<br />"; $timeComp = date("Y-m-d H:i:s", strtotime('+1 day '.$reQuest)); $timeComp = strtotime($timeComp); //echo $timeComp."<br />"; if ($timeNow <= $timeComp){ $timePass=false; }else{$timePass=true;} Hope this helps anyone else who might need this sort of calc. -GS
-
Thank you. You beat me to it. The issue is more that I just want to compare the dates. I thought I was on to something with this little bit of code but I have again hit a wall. $mysqldate = date($reQuest, $phpdate); $phpdate = strtotime($mysqldate); Any more ideas or code snippets would be appreciated. -GS
-
I was trying to avoid the UNIX_TIMESTAMP because of the date limitations placed upon it. Plus, I am not trying to limit the query anyway because I am accessing other information in the table from the database. I need to compare the m in PHP.
-
What I need the code to check is that $reQuest is 24 hours in the past then return a time based on how long ago that was in the past if 24 hours has not passed. if ($reQuest!=""){ if (is_on_interval($phpdate,$getdate,24)==false){ //24 hours has not passed. $timePass=false; //echo $reQuest."<br />"; //debug lines of code //echo phpversion(); // Installed 5.3.1 but still registered as 5.2.2 --odd $start = new DateTime($reQuest); //First or start date to be check as pulled from the database. $time = $start->diff(new DateTime(date("Y-m-d H:i:s", $phptime))); //Check the difference in date with diff() available in 5.3.1 }else{$timePass=true;} } The problem is that 5.3.1 did not install properly and being such I am trying to figure out a new way to get the difference in time from the DateTime in the database and the current time obtained by PHP. The $reQuest variable has a value of 2010-02-18 12:47:15 Any help would be appreciated. Thank you. -GS
-
PHP Force Downloads Spits Up Text Garbage
GreenSmurf replied to GreenSmurf's topic in PHP Coding Help
In the gen.php I forgot this little important line of code and thought I should include it just in case anyone ever decides to use this as a learning tool. Just before the headers there needs to be a line of code that converts the $filename variable back into URL format. Hence this line of code: $filename = urlencode($filename); -GS -
I found this which has the functionality that I am looking for built-in but I am having trouble figuring out how it achieves my goal. I hope that someone may find this useful or can enlighten me should I not find what I am looking for soon. -GS [attachment deleted by admin]
-
PHP Force Downloads Spits Up Text Garbage
GreenSmurf replied to GreenSmurf's topic in PHP Coding Help
This URL pointed me in the right direction. http://www.boutell.com/newfaq/creating/forcedownload.html I hope it helps someone else. So, what I did based on this was I changed this: if($_REQUEST['download'] && $forcedownloads) { $filename = urldecode($_REQUEST['download']); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-Disposition: attachment; filename=".basename($filename).";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); @readfile($filename); exit(0); } to this: $fname = $_REQUEST['download']; echo "<script type=\"text/javascript\">"; echo "window.open(\"gen.php?download=$fname\",\"$fname\", \"resizable,toolbar,scrollbars,menubar,\");"; echo "</script>"; And made gen.php look like this: <?php $allowed_ext = array ( 'zip' => 'application/zip', 'pdf' => 'application/pdf', 'doc' => 'application/msword', 'docx' => 'application/msword', 'docm' => 'application/msword', 'doct' => 'application/msword', 'dotm' => 'application/msword', 'dotx' => 'application/msword', 'dot' => 'application/msword', 'odt' => 'application/msword', 'wpd' => 'application/msword', 'wps' => 'application/msword', 'prn' => 'application/msword', 'xls' => 'application/vnd.ms-excel', 'xl' => 'application/vnd.ms-excel', 'xlsx' => 'application/vnd.ms-excel', 'xlsm' => 'application/vnd.ms-excel', 'xlsb' => 'application/vnd.ms-excel', 'xlam' => 'application/vnd.ms-excel', 'xltx' => 'application/vnd.ms-excel', 'xltm' => 'application/vnd.ms-excel', 'xlt' => 'application/vnd.ms-excel', 'xla' => 'application/vnd.ms-excel', 'xlm' => 'application/vnd.ms-excel', 'xlw' => 'application/vnd.ms-excel', 'qba' => 'application/x-qbmsxml', 'qbb' => 'application/x-qbmsxml', 'qbm' => 'application/x-qbmsxml', 'qbw' => 'application/x-qbmsxml', 'qbx' => 'application/x-qbmsxml', 'gif' => 'image/gif', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg' ); $filename = urldecode($_REQUEST['download']); $fext = strtolower(substr(strrchr($filename,"."),1)); if (!array_key_exists($fext, $allowed_ext)) { die("Not allowed file type."); } if ($allowed_ext[$fext] == '') { $mtype = ''; if (function_exists('mime_content_type')) { $mtype = mime_content_type($file_path);} else if (function_exists('finfo_file')) { $finfo = finfo_open(FILEINFO_MIME); $mtype = finfo_file($finfo, $file_path); finfo_close($finfo); } if ($mtype == '') { $mtype = "application/force-download"; } }else{ $mtype = $allowed_ext[$fext];} header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Type: application/$mtype"); header("Content-Type: application/download"); header("Content-Disposition: attachment; filename=".basename($filename).";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); @readfile($filename); exit(0); ?> And like magic the script works! I knew I was not crazy but eventually we all have our tipping point. Thanks to anyone who PM'd me or even considered my problem. -GS -
Trying to get my force downloads script to work. The example below was actually taken from another script and modified but its similar to the one I originally wrote. if($_REQUEST['download'] && $forcedownloads) { $filename = urldecode($_REQUEST['download']); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-Disposition: attachment; filename=".basename($filename).";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); @readfile($filename); exit(0); } It is pretty basic but the problem occurs when the script outputs this: Any help would be appreciated. Thank you. -GS
-
I am not exactly sure how to word this because I know it is possible but I will try my best. I am attempting to find information on how to limit the file extensions in the file browser before a user submits an upload. I have attached an image of what I am talking about. It by default comes up with All Files (*.*) as the option but I would like to limit it to valid types. I have seen an example script on how to do this before but I forget for the life of me what its called or else I might just Google it. If anyone has any information I would appreciate it. Thank you. -GS [attachment deleted by admin]
-
Upload script. I think I have narrow the error down to this part.
GreenSmurf replied to GreenSmurf's topic in PHP Coding Help
Found the error. It was a check just above the code I provided. Thank you RussellReal for your tip. It made me think about what information was being passed. So, I echoed the information being passed and saw that its was doubling up on the variable $leadon and that made me think what could be causing it. Turns out that this code: if($dirok) { $leadon = $leadon.$_REQUEST['dir']; } Was supposed to be this: if($dirok) { $leadon = $_REQUEST['dir']; } Thank you for your help. Simple fix for a simple problem. -GS -
Allow uploads is true and I have been able to verify that the logic is working properly but the uploading process itself is not. A possible culprit is the variable $leadon which is the directory value for the person logged into their account. The directory is correct and is based on their name and unique member id. For example, my test account has the directory set to User_Name43. if($allowuploads && $_FILES['file']) { $upload = true; if(!$overwrite) { if(file_exists($leadon.$_FILES['file']['name'])) { $upload = false; } } if($upload) { move_uploaded_file($_FILES['file']['tmp_name'], $leadon . $_FILES['file']['name']); } } Any hints at what appears to be wrong would be most appreciated. If you need to see more code I can throw it up but I did not want to burden anyone person's eyes with all the code. -Smurf
-
I believe it has to do with the browser you are using. I am not certain but this problem seems to have vanished now that I am on Firefox 3.5.6 and not an older version or using Internet Explorer. If anyone has experienced similar problems I would like to know how it was resolved within the code or if it is just a lost cause. Thank you. -GS
-
Still have not exactly figured out the error due to the fact that one application of rawurlencode() works and in a very similar (copy-paste) use of the code it does not. The first one does not work. echo "Users added. See on <a href='index.php?group_name=".rawurlencode($group_name)."'>\"$group_name\"</a> or <a href='javascript:history.go(-1)'>Go Back.</a>";[\php] While this one does. [code=php:0]echo "Users removed. See on <a href='index.php?group_name=".rawurlencode($group_name)."'>group page \"$group_name\"</a>."; Any suggestions? I would consider making a URL for each group in the database but then I would have to change quite a bit in the database and in the code due to the fact that it has been left open-ended and generates requests on the fly rather than pulling the info from a database. The other reason is that I wanted to cut down on a need to run queries. I would like to thank you in advanced for any replies and your time. -GS
-
No real reason for choosing one over the other. I just learned rawurlencode first and it works in my other code with similar applications.
-
This one should be pretty easy from what I understand but the problem is I do not have a full understanding. The idea is that $group_name = $myrow["group_name"]; and the "group_name" in the database is "All Darby Clients"; so, there is a a couple spaces nothing too crazy but other group names do have other characters. For all our purposes this particular group will be fine. Here is the code displaying the link: echo "Users added. See on <a href='index.php?group_name=".rawurlencode($group_name)."'>\"$group_name\"</a> or <a href='javascript:history.go(-1)'>Go Back.</a>"; I personally do not see an error here but I keep getting a "Problem Loading Page" error in Firefox and am not too sure as to why. When I click 'Try Again' nothing happens but if I click the URL and hit 'Enter' on the keyboard the page loads with no problem. Any suggestions or tips would be much appreciated. Thank you. -Brandon
-
Some new code: if ($testID == $checkID){ $addUp = false; //echo "<br />".$checkID." == ".$testID."<br /><br />"; $skip[$x] = $checkID; $x++; break; } } if ($addUp == true){ $nume++; } and if ((sizeof($skip) == 0 || !in_array($id, $skip)) || $searchdisplay == false){ Fixed it. Must have been a very long day when I wrote that code. I have no idea what I was thinking. This new code solved it though. -GreenSmurf
-
This solved it. Thanks cags! while ($mycheck = mysql_fetch_array($searchresult2)){ $checkID = $mycheck["id"]; mysql_data_seek($result2,0); $addup = true; while ($mytest = mysql_fetch_array($result2)){ $testID = $mytest["id"]; if ($testID == $checkID){ $addUp = false; break; //echo "<br />".$checkID." != ".$testID."<br /><br />"; } } if ($addUp == true){ $nume++; } } The next thing I have been working on it to create a list of IDs from the table to compare and skip later in the display process but that seems to not be going well. Originally, I simply changed the code to have this code: if ($addUp == true){ $nume++; $skip[$x] = $checkID; $x++; } below the second loop. But I am having trouble with this. The idea is to run a loop later that will check IDs from the query that should be skipped. Since I seem to be completely array illiterate in PHP I have this code right now: while ($i < count($skip)){ $myrow = mysql_data_seek($result,$i); $id = $myrow["id"]; if ($skip[$i] != $id){ ... } } Any more help would be great. Thank you. -GreenSmurf
-
Thank you. I am looking into it now. I am a little unsure how to institute it at this time but I am sure some reading and examples will help. -GreenSmurf
-
while ($mycheck = mysql_fetch_array($searchresult2)){ $checkID = $mycheck["id"]; while ($mytest = mysql_fetch_array($result2)){ $testID = $mytest["id"]; if ($testID != $checkID){ $nume++; echo "<br />".$checkID." == ".$testID."<br /><br />"; } } } I have an interesting bug that seems to not want to go away no many how many times I recode this. The output looks something like this: One part of the problem is that the '40' never changes but I am sure that is related to whatever I am overlooking. It is supposed to check if the IDs from the database match and if so then it is to add an interval to the $nume variable. The reason for the two while loops if because it is check two entirely different queries from a mySQL database. Any help would be appreciated. -GreenSmurf
-
OMG Hax! You got it! Thank you so very much! -Smurf
-
I know double posts are annoying but I wanted to attach the tables being used. [attachment deleted by admin]
-
Thank you xtopolis for your input. I do like the way your query is very clean. I do feel very much like a noob for not concatenating the query. The reason it was stored like that is because I used a script to take celebrity birthdays off of a website and it was the only way I could get it to store. I tried your code and I still get the error: I have been trying to figure out why it does not like the query as it is but have not had too much luck. I will be working more on this soon. Probably tomorrow. If anyone else has suggestions I would appreciate it. -GreenSmurf
-
Thank you. I had noticed that. I forgot to post about it. I changed: (DAYOFYEAR((YEAR(CURDATE()),celebday.bmonth,celebday.bday) to (DAYOFYEAR((YEAR(CURDATE()),celebday.bmonth,celebday.bday)) Now I get this error: -Smurf
-
SELECT * FROM celebday LEFT JOIN month_lookup ON celebday.bmonth=month_lookup.bmonth WHERE I feel this portion is relatively straight forward. The bmonth columns are set equal to one another using left join. (DAYOFYEAR((YEAR(CURDATE()),celebday.bmonth,celebday.bday) This is the portion I believe to be causing the issue. The idea is to get the DAYOFYEAR from the information within its parentheses. Day of year requires year, day, and month. So, I tried to use YEAR() to extract the the current year from CURDATE() and used the table values celebday.bmonth and celebday.bday for the rest of the info. However, the program hiccups here and I get an error that reads: Speak of the devil here is the portion of code the program is talking about: BETWEEN DAYOFYEAR(CURDATE()) AND DAYOFYEAR(ADDDATE(CURDATE(), INTERVAL 2 DAY))) ORDER BY rand() limit 1; Still no idea but I am actively working on it. -GreenSmurf