The Beauty of Old Code
Posted on November 12, 2009
A client of mine needed a quick image upload feature to a custom administration app. We have jQuery and AJAX and all sorts of modern niceness. Screw that.
Bring back PEAR's HTTP_Upload. Its ancient, but justified, if you install the Stable version it was last updated 11-08-2004, five whole years ago.Its a one line install,
pear install HTTP_Upload
I added this to my application,
<p> Customer Logo (optional)<br /> <input type="file" name="CustomerLogo" id="CustomerLogo" /> <br /> </p>
Then the code,
// START CUSTOMER LOGO
require_once "HTTP/Upload.php";
$upload = new HTTP_Upload("en");
$file = $upload->getFiles("CustomerLogo");
if ($file->isValid()) {
$file->setName("uniq");
$UserLogoPath = $file->moveTo('../uploads/customer_logos/');
if (!PEAR::isError($moved)) {
}
else {
echo $moved->getMessage();
}
}
elseif ($file->isError()) {
echo $file->errorMsg();
}
// END CUSTOMER LOGO
Hell, that was easy. I'd have been hacking about for days if I wanted a modern solution!
Related posts
- file_exists(), is_file() & is_dir() with spaces?
Why won't file_exists(), is_file(), is_dir() return true if the file or directory has a space... - Detecting MIME types in PHP
Detecting MIME types in PHP used to be hellish. Use the mime_content_type function I hear... - Chicks dig blokes with groovy login screens
Or how to customise your WordPress login page. There are three main features you may... - I heart MDB2
I recently started a project for a customer, if it's CubeCart, WordPress or BackPress based,... - Install Imagemagick / Imagick for PHP on Ubuntu
No problem if you want to install imagemagick on your server, Ubuntu makes this very...


