|
SmirkingJack posted:Here is a tip that I just had occasion to learn. If you are uploading relatively large files you not only have to make sure that in php.ini not only is upload_max_filesize set high enough but also post_max_size. I could not figure out for the life of me why there was no $_POST variable when I clicked submit until I learned of post_max_size's existence. Thanks for this. I knew about upload_max_filesize but never heard of this. It would've had me frustrated for days.
|
# ¿ Mar 20, 2008 17:10 |
|
|
# ¿ Apr 29, 2024 13:26 |
|
fletcher posted:When I am validating fields submitted from a form I end up with a big if/else like: Whatever you do don't use an if-tree. Can you iterate through an array of testcases/functions and then break? Try using a break or a GOTO of some sort.
|
# ¿ Mar 27, 2008 19:40 |
|
fletcher posted:
php:<? $a=array(aValid,bValid,cValid); $b=array("a error","b error","c error"); function test($a,$b) { for($i=0;$i<count($a);$i++)if(!$a[$i])return $b[$i]; return "all clear!"; } ?>
|
# ¿ Mar 27, 2008 19:43 |
|
fletcher posted:How do I put my test cases in the array? Let's say I'm doing a ctype_digit() on aValid and making sure it's < someValue. Or do I do that before and just stuff the result in the array? If your tests are not time intensive, why not simply run all of them and then check at the end to see if one failed? This is what I usually do. Actually, I keep a stack of error messages and then check to see if it's non-empty. php:<? $err=$array(); if(!$aValid) $err[]="a failed"; if(!$bValid) $err[]="b failed"; if(!$cValid) $err[]="c failed"; if(count($err)) echo "errors"; else echo "we're good"; ?> There are some function pointer things you can do, but to be honest it already looks like your situation is too complex for them, and it's a hassle in PHP anyway. Congratulations, you're smarter than your programming language. functional fucked around with this message at 20:13 on Mar 27, 2008 |
# ¿ Mar 27, 2008 20:08 |
|
(I would prefer a string solution to this, or something built into the PHP library, and not some big package I have to install.) I have a string which consists of potentially bad XML. I have a tag <mytag> which may exist in the XML multiple times. I want to return the text contained in first instance of <mytag>, or the empty string if it doesn't exist. So in the following instance: php:<? <html> <mytag>THIS_IS_THE_STRING</mytag> <span>aaaaaa</span> <html> ?> Is there something that already does this or do I have to write it myself?
|
# ¿ Mar 27, 2008 21:09 |
|
bt_escm posted:http://us.php.net/simplexml Thank you functional fucked around with this message at 21:32 on Mar 27, 2008 |
# ¿ Mar 27, 2008 21:13 |
|
That code is hard to read. Why don't you escape your variables before constructing your query string?
|
# ¿ Mar 31, 2008 01:53 |
|
This isn't always working like it should. I have a special link on my pages that will take you to loggingout.php. It uses a token to verify that you actually clicked the link (and didn't have anyone IM you a fake logout link). Stripping away the logic what it really does is this, which should log you out and redirect you to the index:php:<? LOGGINGOUT.PHP setcookie('blargh','',time()-$tenyears,myCookiePath(),myCookieDomain()); header('Location: http://website.com/theindexpage.php'); ?> What's the deal?
|
# ¿ Jun 12, 2008 04:07 |
|
MrEnigma posted:caching probably, browser still you were cached, try adding some no cache headers and it should fix it. Do you mean to add no-caching headers to the page that looks like you're still logged in? There's a lot of different caching stuff you can do. Can you elaborate? Maybe post some source to get me started?
|
# ¿ Jun 12, 2008 19:26 |
|
dancavallaro posted:This looks great, but because of the way this comment module is designed, I really just want a script that generates a captcha image - that would be the easiest solution. Is there a such thing as any library or script that generates pretty tough captchas? http://www.google.com/search?q=php+captcha+generator
|
# ¿ Jun 17, 2008 04:43 |
|
Evil Angry Cat posted:I just can't fathom why anyone thought this would be a good idea? Why is it that they've decided that numeric keys are completely useless and no would ever use them associatively? I mean there has to be a reason doesn't there? Please can someone explain to me why someone lacked such basic sense as to automatically re-index an array thats being sorted by an integer based key? Gah sometimes PHP. I think I see what you're getting at. Unfortunately things don't work out for you in this instance, but overall it makes more sense to do what they're doing. The reason is that all PHP arrays are associative, but 'unkeyed' arrays typically rely on keyed values to determine order. It wouldn't make sense for me to create $a=Array('Z','Y','X') and have $a[0] return the same value before and after the sort. I wasn't aware before that there are PHP functions which will step through a list in the order it's stored, even if some of the keys are integers that are out of order. This is good to know. php:<? $a=Array(1=>'A', 0=>'B');//Same as $a=Array('1'=>'A', '0'=>'B'); echo $a[0];//B foreach($a as $i)echo $i;//AB for($i=0;$i<count($a);$i++)echo $a[$i];//BA ?> functional fucked around with this message at 16:10 on Jul 9, 2008 |
# ¿ Jul 9, 2008 16:06 |
|
Evil Angry Cat posted:If only they'd give me the option though like they do with all of their other barmy array functions I'd be happy. Yep, you're right. There ought to be an option for what you want to do. I would submit a feature request. It shouldn't be a difficult change to implement. (Presuming asort() is insufficient for your application.) functional fucked around with this message at 21:20 on Jul 9, 2008 |
# ¿ Jul 9, 2008 21:13 |
|
Poker Sort Assume an array of non-negative integers. They should be sorted in descending order, except if an integer A is present X times in the list, all A should come before all B present Y<X times in the list, and all A should come after all C present Z>X times in the list, and all A should be sorted descending versus any D present X times in the lest. Bonus Credit given for the best and shortest answer. Example: php:<? L =52126723644689 //These are actually arrays and not strings S(L)=66622244987531 ?> functional fucked around with this message at 15:20 on Aug 11, 2008 |
# ¿ Aug 11, 2008 14:36 |
|
chocojosh posted:Does this look like the homework help thread? You may be confused because I took the time to write a nice problem description. (Nobody does homework in PHP. And I am not a student.)
|
# ¿ Aug 11, 2008 17:33 |
|
thedaian posted:Anyway, there's a ton of different php sort functions. Try one of those. If you've got a specific issue with your code, then we can probably help. We're not here to do all your work for you. Actually the problem is that all of the PHP sort functions are broken in some way. The natural approach would be to "group" the number of values, for instance, keeping an array with keys for the values 1-9. php:<? [1] => 2 [2] => 0 ... [9] => 1 ?> You could then flip the array, and get a sorted map which would solve the problem. Unfortunately PHP won't let you have repeated keys, so if there are two 1s and two 9s, you get a collision and you lose. And instead of lumping those two values into an array under the same key, it just drops one of them, so you also lose. You would think you could do the same thing using asort, but again, PHP will sort the array values, but it's a destructive sort with respect to key order! You can't guarantee 9 will come before or after 1. Instead of having one nice sort that works, PHP has ten different sorts, none of which works. This is an easy problem in several other languages. It is not trivial in PHP. It is typical though of the kind of thing PHP programmers have to deal with, which is why I posted it here. functional fucked around with this message at 22:26 on Aug 11, 2008 |
# ¿ Aug 11, 2008 22:21 |
|
DaTroof posted:It's really not all that non-trivial. Here's a solution I hacked together in a few minutes. Interesting approach to the problem. I kept trying to find a functional solution. I had thought about using a special comparator but I couldn't figure out how to tell it the external $count data. I never thought about using objects.
|
# ¿ Aug 12, 2008 16:50 |
|
Agrikk posted:Without manipulating the data in the database, how can I force PHP to produce a page that displays the <> characters? htmlspecialchars
|
# ¿ Aug 14, 2008 19:17 |
|
LastCaress posted:Is there a simple lightweight php script (and free) that allows users to upload pictures (like gallery) that I can install in my site? Basically something that doesn't require registration or anything else, just an upload button and you're done. R1ch put out a secure PHP script that did this. I don't have search enabled so I can't find it for you, but that should put you on the right track.
|
# ¿ Aug 16, 2008 01:41 |
|
Gibbon_WBA posted:Argh I thought I had it then! but no there's still no output on the final page (where is shows the user what he/she has inputted on the previous pages), there's nothing Let me show you how to refactor this type of block... All the typing you're doing is hurting me. php:<? $s='name address dateofbirth username'; //And so on... $a=explode(' ',$s); foreach($a as $x)$$x=$_SESSION[$x]; foreach($a as $x)echo $$x; echo $name; //works ?>
|
# ¿ Aug 18, 2008 20:15 |
|
Battle Bott posted:It seems to work, but viewing things like flash movies forces a browser download rather than viewing it in browser... As I recall you can decide which of these behaviors you want by manipulating the header field. quote:and I don't know how it would handle very large files. (multi-hundered mb) I did this with <10 meg files and never had a problem. When I was implementing it I came across a remark, I believe on the PHP website, which claimed it was faster to read the file in chunks than to use readfile. I never noticed a difference, but then I never used really big files. quote:Is this a horrible idea? Can it be implemented better? It's fine on moderately sized sites. I can't comment for or against on very high traffic sites. I'm worried about your code, though. Lines like these: php:<? #url.com/filesupersystem/dl.php?file=image.jpg $fullfile="mydirectory/$file"; ?> Anyway, do you have a legitimate reason to be concerned about leeching? functional fucked around with this message at 04:20 on Jan 12, 2009 |
# ¿ Jan 12, 2009 04:07 |
|
|
# ¿ Apr 29, 2024 13:26 |
|
Battle Bott posted:Something like http://wettone.com/code/slimstat, except prettier. This is good and all...and I admire your productive attitude...but if this is all you're doing, and you don't care about leeching (and apparently, file substitution), why don't use just use some kind of webserver stats plugin? What are you trying to accomplish? You've piqued my curiosity. functional fucked around with this message at 19:16 on Jan 12, 2009 |
# ¿ Jan 12, 2009 19:11 |