This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create two files: | |
PHP file get_image.php: | |
<?php | |
//you'll play with dirs / paths later | |
$file = 'some_image.png'; | |
$type = 'image/png'; | |
header('Content-Type:'.$type); | |
header('Content-Length: ' . filesize($file)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Disclaimer - I am aware using __call to set things isn't anything new, once upon a time, I created an ORM class doing that, but this | |
* time I'd like to ask about using this approach actually everytime we need accessors like set/get. | |
* | |
* OK, so using accessors is a good practice. But quite boring, isn't it? Even with all this IDEs' support (menu code -> create accessors for me please). | |
* | |
* Why not use the __call magic method catching "get/set" methods? | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
Here is an example of type hinting variables (not function parameters), using php doc. | |
There is only one reason for doing this - to let IDEs know what is what. | |
*/ | |
class X{ | |
public function blahx(){ | |
echo 'blahx'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
It's about a different way of passing params to an sql query. Yes, still using PDO behind the scenes. | |
*/ | |
/////////////////////////// | |
//The standard way of passing params: | |
$stmt = $dbh->prepare("INSERT INTO some_table (first_name, last_name) VALUES (?, ?)"); | |
$stmt->bindValue(1, $_GET['first_name']); |
NewerOlder