-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
That's a JPEG 2000 image, not PNG. You can't just name a file what you want and expect it to work. With that said, renaming with the appropriate extension (a) isn't enough because there's more to the issue than just the extension and (b) really isn't enough because it's JPEG 2000 and that format isn't commonly supported. Convert it to a different format.
-
Since the weight and dimension are properties, not objects, this is technically more of a "strategy" than a "factory". Though you may very well use a factory to get the strategy, or go with a more dependency-injected route. Not knowing the entire application, I'd go with a base class that provides the weight and dimensions. When a value is available, it is used, and when the value is not available, it does stuff to calculate (and then update) the value. abstract class Fruit { private $weight; private $dimensions = array(); // [w, h, d] public function getWeight() { if (!$this->weight) { if ($this->dimensions) { $this->weight = FruitStrategy::factory($this)->getWeight($this->dimensions); } else { // not enough information } } return $this->weight; } } class Apple extends Fruit { } class Pear extends Fruit { } abstract class FruitStrategy { public static function factory(Fruit $fruit) { $class = get_class($fruit) . "Strategy"; return new $class(); } public abstract function getWeight($dimensions); } class AppleStrategy extends FruitStrategy { public function getWeight($dimensions) { return 0.5 * $dimensions[0] * $dimensions[1] * $dimensions[2]; } }Even further, getWeight will probably look about the same for everything. So why not provide a default implementation? abstract class FruitStrategy { public static function factory(Fruit $fruit) { $class = get_class($fruit) . "Strategy"; return new $class(); } public function getWeight($dimensions) { return $this->getWeightMultiplier() * $dimensions[0] * $dimensions[1] * $dimensions[2]; } protected abstract function getWeightMultiplier(); } class AppleStrategy extends FruitStrategy { protected function getWeightMultiplier() { return 0.5; } }
-
array_filter and count not acting as expected
requinix replied to davidannis's topic in PHP Coding Help
By the way, you don't need array_filter(). I think that's intended to filter out the checkboxes that weren't checked? In HTML only the checkboxes that were checked will be submitted. As that print_r() output shows. -
There would only be a redirect if there was something telling Apache (or maybe it's in your code?) to do so. I don't know enough about your system to tell you where that is. If it's not code then often it's in a .htaccess; in this case there would be something very much like what you've just posted: RewriteCond <if the HTTP_HOST is not the subdomain> RewriteRule <to the subdomain>The domain would have to be pointing (DocumentRoot) to the same location as the subdomain, thus the .htaccess would kick in and redirect.If it's in code then it could be anything, anywhere. Now I'm kinda lost to what the problem is. You were talking about domain->subdomain redirecting being a problem. The stuff you posted redirects everything from not newdomain.com to test.othersite.com (and I have no idea which of those domain names correspond to what sites). So let's backtrack a bit. You have a parked domain. Let's call it "parkeddomain.com". 1. Being parked, there won't be any content there, and instead it'll (apparently) redirect? 2. Does this parked domain have subdomains? Just to be sure. I don't think it does. 3. What is its purpose if all it does is redirect? You also have a regular domain, "domain.com", and per-user subdomains, say "user.domain.com". 4. What are the redirects? From which site(s) to which other site(s)? 5. What do you already have in place for your .htaccess files and/or virtualhost configurations? 6. What is it doing now that you don't want?
-
Apache does not have the suPHP module loaded. It's that simple. Talk to your hosting company to see what's up with it.
-
Simplest solution? When before you were returning JSON for a single comment, now you return an array of the exact same stuff for each comment. When before you were dealing with data as representing a single comment, now you loop over it as the array it is and inside do (roughly) the same logic you have now. But now you won't be able to use elements by ID because you'll need more than one, so first you'll have to restructure your HTML a bit to accommodate.
-
There's also b) Since SimpleXML is technically an extension, php -m on the command line to list all extensions, or c) extension_loaded in your code d) class_exists for the SimpleXMLElement class
-
Make the file be PHP instead of straight HTML. All you have to do is change the extension to .php (and make sure there's no "<?php" PHP markup in it). Then you can start putting PHP code into it for the dynamic features, and the calling code can use include to execute it. include "code.php";If you want to vary bits of the content then use can use variables for it. Like in the calling code you have $show_gs = false; include "code.php";and in the code.php you have ... <?php if (!isset($show_gs) || $show_gs) { /* calling code didn't set $show_gs, or it did and set it to true */ ?> <script type="text/javascript"> GS_googleEnableAllServices(); </script> <?php } ?> ...There are more powerful methods depending on how your application is set up, though mostly to do with how this code.htm file works and is used.
-
Static Methods vs. Singleton vs. Dependency/constructor Injection
requinix replied to adam_bray's topic in PHP Coding Help
"Anti-design" does not mean something is bad. It means it's easy to abuse the design towards a bad end. Registries, singletons, static members, being anti-design means that you should think about how you are using them, not that you have to avoid them entirely. I could go for any of: a) A registry of the values, as you do need to propagate values across multiple locations b) A singleton for the various objects, but only if there are never multiple configuration files, configuration objects, or database connections c) Dependency injection by way of variables: have loadPage() set values, maybe looking like print $content->loadPage($_GET['page'], array('db' => $db));and then you'll have $db (or $this->db or whatever) set for you. This actually shares a lot in common with (a). -
jquery ajax .complete forgets what was clicked
requinix replied to michaellunsford's topic in Javascript Help
As you seem to have realized, this inside the complete handler is not the same as the one inside the top click handler. Because it's all asynchronous. Use a local variable. $('table td').click(function() { var self = $(this); alert(self.index()); $.ajax({ url: "update.php", type: "POST", data: { action: 'clicked', clicked: self.index(), row: self.parent().attr('id').substr(4) } }) .complete(function(data) { alert(self.index()); console.log(data.responseText); self.attr('id','ros'+data.responseText); }); } -
You don't actually run that script from a Cygwin shell. Read what he actually wrote: He grabbed the df executable and put that in an accessible place. The commands there go in a regular Windows batch file, not a bash script. But ugh, that whole thing makes me feel dirty just looking at it. Disk usage information should be calculated using something like PowerShell and some WMI queries against the hosting servers.
-
That's batch file syntax, for Windows. You can't use it in Cygwin, a Linux environment.
-
Jacques1 was hoping you would reply with something like If that's half true then you don't have your environment set up to tell you about problems: find your php.ini, set error_reporting = -1 display_errors = onand restart your web server. Then try the script and see what you get. There's no output because Counter() doesn't return anything to output. You get the undefined variable warnings because $count, while defined outside the function, is not defined inside the function. You don't get that variable for free. The global thing is one solution but you should avoid it. I personally would have suggested the static $count thing you have now.
- 5 replies
-
- php functions
- php
-
(and 1 more)
Tagged with:
-
Most of the time, the regex you're using is compatible with PCRE functions... as long as you wrap it with delimiters. Pick a character that you aren't using in the regex, often / or # or ~, or pick one you are using an escape it wherever you do, and put it at the beginning and end of the expression. '/[-a-z0-9!#$%&\'*+\/=?^_`{|}~]+@([.]?[a-zA-Z0-9_\/-])*/' // escaped the two /sIf you want case-insensitive expressions, like with eregi() and eregi_replace(), then use the i flag. It goes after the last delimiter. '/[-a-z0-9!#$%&\'*+\/=?^_`{|}~]+@([.]?[a-zA-Z0-9_\/-])*/i'
-
Your query only retrieves the name and password. If you want the email too then you need to include that. Why are you grabbing the password? You don't need it once they've logged in.
-
... If all the characters are numerical then it is an integer.
-
Anyone using Google or Amazon cloud for hosting?
requinix replied to michaellunsford's topic in Miscellaneous
- You get a dedicated machine so you can do whatever you want to it - Uptime depends almost entirely on you and the rest can be minimized by using a redundant architecture (eg, multiple machines in different locations) - For us, scalability is handled by loading balancing and firing up more machines (happens automatically) when needed -
Anyone using Google or Amazon cloud for hosting?
requinix replied to michaellunsford's topic in Miscellaneous
My company uses Amazon. Any particular questions? -
array_intersect() only checks values - not keys. Maybe you want array_intersect_assoc?
-
You got the public_id from somewhere, right? Database? When the form is posted back, make sure you can (re)find that public_id for the user. Like if you wanted to edit your post, there's a form that has the post ID. When you submit, the forum checks that the post is one of yours and only lets you edit if it is.
-
A bit backwards, yes? I see you're grabbing the error code. Why aren't you checking it? You need to check that code to see what happened. Maybe the upload worked. Maybe the upload failed. Maybe the file was partially uploaded. You won't know until you check that error code. While I'm at it, $fileType is not safe to use. The browser told you the type of file and for all you know the user told the browser to lie about that. You have to figure out the file type by yourself. For images you can use getimagesize. The $fileName is not safe either. It can be absolutely anything the user wanted it to be and checking the file type, even by yourself, is not enough to be safe. For images specifically, unless they're too large you can load them into memory (so that PHP does a little bit of processing) and then save them out to the location you want with the name you want. Make sure it has the right extension too. Speaking of names, you're not doing anything to check for overwriting files. Do you want that to happen?
-
List all files in dir, then put content of files into array
requinix replied to mikk809h's topic in PHP Coding Help
Sure. What did you try and how didn't it work? I'm sure it'll be easier to fix that than to try writing it all from scratch.