home gear home donate
Search Results For

Libraries book

HTML Library CSS Library JavaScript Library PHP Library


PHP and MySQL JavaScript HTML and CSS Vector and 3D Flash Actionscript Android Dev Miscellaneous


Website Hosting Developer Q+A
Sprite Programming Mastery
<iframe width="560" height="315" src="" frameborder="0" allowfullscreen></iframe>
You can embed this video on your blog or web page by copying the video embed code above and pasting it into the source code of your page. Adjust the width and height to specify the size you would like it to display.
Thumb Build a PHP Image Upload Application to Enable Working With Images On the Fly
Embed Source -
Publish Date - Mar 16, 2011     Author - Adam Khoury
Build a PHP Image Upload Application to Enable Working With Images On the Fly
Master PHP Image Processing with Adam Khoury in this Video Textbook Series. In this video we learn to build a basic PHP image file upload application so we have a way to work with images on the fly. Which means automatically at runtime upon upload of an image file.
Lesson Code
<!-- -------------------------------------------- -->
<!-- "my_file.php" that has the simple form on it -->
<!-- -------------------------------------------- -->

<form enctype="multipart/form-data" method="post" action="image_upload_script.php">
Choose your file here:
<input name="uploaded_file" type="file"/><br /><br />
<input type="submit" value="Upload It"/>

<!-- -------------------------------------------- -->
<!-- "image_upload_script.php" -->
<!-- -------------------------------------------- -->

// Access the $_FILES global variable for this specific file being uploaded
// and create local PHP variables from the $_FILES array of information
$fileName $_FILES["uploaded_file"]["name"]; // The file name
$fileTmpLoc $_FILES["uploaded_file"]["tmp_name"]; // File in the PHP tmp folder
$fileType $_FILES["uploaded_file"]["type"]; // The type of file it is
$fileSize $_FILES["uploaded_file"]["size"]; // File size in bytes
$fileErrorMsg $_FILES["uploaded_file"]["error"]; // 0 = false | 1 = true
$kaboom explode("."$fileName); // Split file name into an array using the dot
$fileExt end($kaboom); // Now target the last array element to get the file extension
// START PHP Image Upload Error Handling --------------------------------------------------
if (!$fileTmpLoc) { // if file not chosen
echo "ERROR: Please browse for a file before clicking the upload button.";
} else if(
$fileSize 5242880) { // if file size is larger than 5 Megabytes
echo "ERROR: Your file was larger than 5 Megabytes in size.";
unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
} else if (!
preg_match("/.(gif|jpg|png)$/i"$fileName) ) {
// This condition is only if you wish to allow uploading of specific file types    
echo "ERROR: Your image was not .gif, .jpg, or .png.";
unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
} else if (
$fileErrorMsg == 1) { // if file upload error key is equal to 1
echo "ERROR: An error occured while processing the file. Try again.";
// END PHP Image Upload Error Handling ----------------------------------------------------
// Place it into your "uploads" folder mow using the move_uploaded_file() function
$moveResult move_uploaded_file($fileTmpLoc"uploads/$fileName");
// Check to make sure the move result is true before continuing
if ($moveResult != true) {
"ERROR: File not uploaded. Try again.";
unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
// Display things to the page so you can see what is happening for testing purposes
echo "The file named <strong>$fileName</strong> uploaded successfuly.<br /><br />";
"It is <strong>$fileSize</strong> bytes in size.<br /><br />";
"It is an <strong>$fileType</strong> type of file.<br /><br />";
"The file extension is <strong>$fileExt</strong><br /><br />";
"The Error Message output for this upload is: $fileErrorMsg";

Home   •   Terms of Use   •   T-Shirts   •   RSS   •   Testimonials   •   Subscribe   •   Classroom Chalkboard   •   Developer Q+A   •   Donate   •   Top ↑
Popular In PHP / MySQL E-Commerce Store Production
Social Network Website Building
Image Upload / Photo Processing
CMS Software Programming
Mass Email Systems
Magic XML Data
Search Programming
Popular In JavaScript JSON Programming
Ajax Programming
Animating Elements
WYSIWYG Programming
Date/Time Programming
DOM Scripting
Object Reference
Popular In HTML Canvas Element
New Form Elements
Audio Element
Video Element
Drag and Drop
Event Handling
Element Grouping
Popular In CSS Custom Font Embedding
Dynamic Fit Backgrounds
Theatre Mode
Box Overlays
CSS Level 1 Properties
CSS Level 2 Properties
CSS Level 3 Properties is a growing educational system packed with video and written material that you can access 24/7 100% free. The focus here in 2014 is spread between five technologies: HTML, CSS, JavaScript, PHP and MySQL. Learn programming theory, database interaction, web design, animation, graphics editing, vector art, 3D modeling, and much more. The educational experience here is a hybrid one offering both high quality video tutorials and code libraries that grow more robust every day. The code libraries are being assembled so that developers can discover all of the building blocks of their favorite languages. The libraries coupled with high quality video tutorials will take you deep down the rabbit hole very quickly. You can also ask questions and get free advice at