Dark Launch

This is a Dark Launch.

PHP implode_with_key(); Implode array with key and value

PHP
 
function implode_with_key($assoc, $inglue = '>', $outglue = ',') {
$return = '';
 
foreach ($assoc as $tk => $tv) {
$return .= $outglue . $tk . $inglue . $tv;
}
 
return substr($return, strlen($outglue));
}

PHP implode_wrapped(); Implode with before and after

UPDATED:
PHP
 
function implode_wrapped($before, $after, $array, $glue = '') {
return $before . implode($after . $glue . $before, $array) . $after;
}

OLD:
PHP
 
function implode_wrapped($before, $after, $glue, $array) {
$output = '';
 
foreach ($array as $item) {
$output .= $before . $item . $after . $glue;
}
 
return substr($output, 0, -strlen($glue));
}

How to fix SVN Error Commit failed; Unable to open an ra_local session to URL

You may get this error if your svn repository moved:
Code
 
svn: Commit failed (details follow):
svn: Unable to open an ra_local session to URL
svn: Unable to open repository 'file:///path/to/repository'
 

You will need to relocate your svn source repository.
Here's the scenario:
Code
 
Repository was located in:
file:///home/user/var/www/repositories/www.example.com/
 
Repository moved to:
file:///home/user/mounts/www.example.com/web/repository/
 
Files are located in:
/var/www/www.example.com/
 

Open terminal and do the following to update the location of the repository:
Check where the current location of the repository is using:
Code
 
cd /var/www/www.example.com/
svn info
 

Look for "Repository Root:" ("file:///home/user/var/www/repositories/www.example.com/")
Now to switch the repository root, do the following:
Code
 
cd /var/www/www.example.com/
svn switch --relocate file:///home/user/var/www/repositories/www.example.com/ file:///home/user/mounts/www.example.com/web/repository/
 

That is, svn switch --relocate old_repo new_repo.
Again, do svn info to check that the repository root has been updated.
Code
 
svn info
 

NOTE: Remember there are three (3) slashes after file in file:///

Import MySQL Backup; Restore .SQL Export

Open a terminal and type the following:
Code
 
mysql -u USERNAME -p -h SERVER DATABASE < "/path/to/backup.sql"
 

Replace USERNAME, SERVER, DATABASE and "/path/to/backup.sql".
Example:
Code
 
mysql -u someuser -p -h 127.0.0.1 mydatabase < "~/Desktop/mybackup.sql"
 

Once complete, mybackup.sql will have been imported into mydatabase.

Reuse Kate Text Editor Instance; Open files reusing same window

To tell Kate Advanced Text Editor to re-use any already open windows, do the following:
Code
 
1. Right click on the file to open with Kate and select Properties > Open With tab.
2. In the new window, click the Add button.
3. At the bottom under "Use a custom command" type: kate -u %U and click Add.
4. Select the newly added open with application and Close the window.
 

Now opening multiple files associated with Kate will re-use the existing window.
The -u tells Take to open files in the same Kate instance.
NOTE: or use '/usr/bin/kate' -u %U

HTML Color Names; HTML Color Codes

XML
 
<color name="AliceBlue" value="#F0F8FF"/>
<color name="AntiqueWhite" value="#FAEBD7"/>
<color name="Aqua" value="#00FFFF"/>
<color name="Aquamarine" value="#7FFFD4"/>
<color name="Azure" value="#F0FFFF"/>
<color name="Beige" value="#F5F5DC"/>
<color name="Bisque" value="#FFE4C4"/>
<color name="Black" value="#000000"/>
<color name="BlanchedAlmond" value="#FFEBCD"/>
<color name="Blue" value="#0000FF"/>
<color name="BlueViolet" value="#8A2BE2"/>
<color name="Brown" value="#A52A2A"/>
<color name="BurlyWood" value="#DEB887"/>
<color name="CadetBlue" value="#5F9EA0"/>
<color name="Chartreuse" value="#7FFF00"/>
<color name="Chocolate" value="#D2691E"/>
<color name="Coral" value="#FF7F50"/>
<color name="CornflowerBlue" value="#6495ED"/>
<color name="Cornsilk" value="#FFF8DC"/>
<color name="Crimson" value="#DC143C"/>
<color name="Cyan" value="#00FFFF"/>
<color name="DarkBlue" value="#00008B"/>
<color name="DarkCyan" value="#008B8B"/>
<color name="DarkGoldenRod" value="#B8860B"/>
<color name="DarkGray" value="#A9A9A9"/>
<color name="DarkGreen" value="#006400"/>
<color name="DarkKhaki" value="#BDB76B"/>
<color name="DarkMagenta" value="#8B008B"/>
<color name="DarkOliveGreen" value="#556B2F"/>
<color name="Darkorange" value="#FF8C00"/>
<color name="DarkOrchid" value="#9932CC"/>
<color name="DarkRed" value="#8B0000"/>
<color name="DarkSalmon" value="#E9967A"/>
<color name="DarkSeaGreen" value="#8FBC8F"/>
<color name="DarkSlateBlue" value="#483D8B"/>
<color name="DarkSlateGray" value="#2F4F4F"/>
<color name="DarkTurquoise" value="#00CED1"/>
<color name="DarkViolet" value="#9400D3"/>
<color name="DeepPink" value="#FF1493"/>
<color name="DeepSkyBlue" value="#00BFFF"/>
<color name="DimGray" value="#696969"/>
<color name="DodgerBlue" value="#1E90FF"/>
<color name="FireBrick" value="#B22222"/>
<color name="FloralWhite" value="#FFFAF0"/>
<color name="ForestGreen" value="#228B22"/>
<color name="Fuchsia" value="#FF00FF"/>
<color name="Gainsboro" value="#DCDCDC"/>
<color name="GhostWhite" value="#F8F8FF"/>
<color name="Gold" value="#FFD700"/>
<color name="GoldenRod" value="#DAA520"/>
<color name="Gray" value="#808080"/>
<color name="Green" value="#008000"/>
<color name="GreenYellow" value="#ADFF2F"/>
<color name="HoneyDew" value="#F0FFF0"/>
<color name="HotPink" value="#FF69B4"/>
<color name="IndianRed" value="#CD5C5C"/>
<color name="Indigo" value="#4B0082"/>
<color name="Ivory" value="#FFFFF0"/>
<color name="Khaki" value="#F0E68C"/>
<color name="Lavender" value="#E6E6FA"/>
<color name="LavenderBlush" value="#FFF0F5"/>
<color name="LawnGreen" value="#7CFC00"/>
<color name="LemonChiffon" value="#FFFACD"/>
<color name="LightBlue" value="#ADD8E6"/>
<color name="LightCoral" value="#F08080"/>
<color name="LightCyan" value="#E0FFFF"/>
<color name="LightGoldenRodYellow" value="#FAFAD2"/>
<color name="LightGrey" value="#D3D3D3"/>
<color name="LightGreen" value="#90EE90"/>
<color name="LightPink" value="#FFB6C1"/>
<color name="LightSalmon" value="#FFA07A"/>
<color name="LightSeaGreen" value="#20B2AA"/>
<color name="LightSkyBlue" value="#87CEFA"/>
<color name="LightSlateGray" value="#778899"/>
<color name="LightSteelBlue" value="#B0C4DE"/>
<color name="LightYellow" value="#FFFFE0"/>
<color name="Lime" value="#00FF00"/>
<color name="LimeGreen" value="#32CD32"/>
<color name="Linen" value="#FAF0E6"/>
<color name="Magenta" value="#FF00FF"/>
<color name="Maroon" value="#800000"/>
<color name="MediumAquaMarine" value="#66CDAA"/>
<color name="MediumBlue" value="#0000CD"/>
<color name="MediumOrchid" value="#BA55D3"/>
<color name="MediumPurple" value="#9370D8"/>
<color name="MediumSeaGreen" value="#3CB371"/>
<color name="MediumSlateBlue" value="#7B68EE"/>
<color name="MediumSpringGreen" value="#00FA9A"/>
<color name="MediumTurquoise" value="#48D1CC"/>
<color name="MediumVioletRed" value="#C71585"/>
<color name="MidnightBlue" value="#191970"/>
<color name="MintCream" value="#F5FFFA"/>
<color name="MistyRose" value="#FFE4E1"/>
<color name="Moccasin" value="#FFE4B5"/>
<color name="NavajoWhite" value="#FFDEAD"/>
<color name="Navy" value="#000080"/>
<color name="OldLace" value="#FDF5E6"/>
<color name="Olive" value="#808000"/>
<color name="OliveDrab" value="#6B8E23"/>
<color name="Orange" value="#FFA500"/>
<color name="OrangeRed" value="#FF4500"/>
<color name="Orchid" value="#DA70D6"/>
<color name="PaleGoldenRod" value="#EEE8AA"/>
<color name="PaleGreen" value="#98FB98"/>
<color name="PaleTurquoise" value="#AFEEEE"/>
<color name="PaleVioletRed" value="#D87093"/>
<color name="PapayaWhip" value="#FFEFD5"/>
<color name="PeachPuff" value="#FFDAB9"/>
<color name="Peru" value="#CD853F"/>
<color name="Pink" value="#FFC0CB"/>
<color name="Plum" value="#DDA0DD"/>
<color name="PowderBlue" value="#B0E0E6"/>
<color name="Purple" value="#800080"/>
<color name="Red" value="#FF0000"/>
<color name="RosyBrown" value="#BC8F8F"/>
<color name="RoyalBlue" value="#4169E1"/>
<color name="SaddleBrown" value="#8B4513"/>
<color name="Salmon" value="#FA8072"/>
<color name="SandyBrown" value="#F4A460"/>
<color name="SeaGreen" value="#2E8B57"/>
<color name="SeaShell" value="#FFF5EE"/>
<color name="Sienna" value="#A0522D"/>
<color name="Silver" value="#C0C0C0"/>
<color name="SkyBlue" value="#87CEEB"/>
<color name="SlateBlue" value="#6A5ACD"/>
<color name="SlateGray" value="#708090"/>
<color name="Snow" value="#FFFAFA"/>
<color name="SpringGreen" value="#00FF7F"/>
<color name="SteelBlue" value="#4682B4"/>
<color name="Tan" value="#D2B48C"/>
<color name="Teal" value="#008080"/>
<color name="Thistle" value="#D8BFD8"/>
<color name="Tomato" value="#FF6347"/>
<color name="Turquoise" value="#40E0D0"/>
<color name="Violet" value="#EE82EE"/>
<color name="Wheat" value="#F5DEB3"/>
<color name="White" value="#FFFFFF"/>
<color name="WhiteSmoke" value="#F5F5F5"/>
<color name="Yellow" value="#FFFF00"/>
<color name="YellowGreen" value="#9ACD32"/>

I used these for gEdit themes.

Firefox Disable iframes; about:config > browser.frames.enabled

In the address bar go to about:config.
In the Filter: browser.frames.enabled
Double click the value to toggle from true to false.
Open a new window for changes to appear.
Code
 
about:config
browser.frames.enabled = false
 

Firefox Disable iframes; about:config > browser.frames.enabled

In the address bar go to about:config.
In the Filter: browser.frames.enabled
Double click the value to toggle from true to false.
Open a new window for changes to appear.

PHP xml_encode using DOMDocument; Convert Array to XML; json_encode

Encode XML using xml_encode(); similar to json_encode().
PHP
 
function xml_encode($mixed,$domElement=null,$DOMDocument=null){
if(is_null($DOMDocument)){
$DOMDocument=new DOMDocument;
$DOMDocument->formatOutput=true;
xml_encode($mixed,$DOMDocument,$DOMDocument);
echo $DOMDocument->saveXML();
}
else{
if(is_array($mixed)){
foreach($mixed as $index=>$mixedElement){
if(is_int($index)){
if($index==0){
$node=$domElement;
}
else{
$node=$DOMDocument->createElement($domElement->tagName);
$domElement->parentNode->appendChild($node);
}
}
else{
$plural=$DOMDocument->createElement($index);
$domElement->appendChild($plural);
$node=$plural;
if(rtrim($index,'s')!==$index){
$singular=$DOMDocument->createElement(rtrim($index,'s'));
$plural->appendChild($singular);
$node=$singular;
}
}
xml_encode($mixedElement,$node,$DOMDocument);
}
}
else{
$domElement->appendChild($DOMDocument->createTextNode($mixed));
}
}
}

Example:
PHP
 
$data=array();
for($i=0;$i<3;$i++){
$data['users'][]=array(
'name'=>'user'.$i,
'img'=>'http://example.com/user'.$i.'.png',
'website'=>'http://example.com/'
);
}
 
header('Content-type: application/xml');
echo xml_encode($data);
 
/*
<users>
<user>
<name>user0</name>
<image>http://example.com/user0.png</image>
<website>http://example.com/</website>
</user>
<user>
<name>user1</name>
<image>http://example.com/user1.png</image>
<website>http://example.com/</website>
</user>
<user>
<name>user2</name>
<image>http://example.com/user2.png</image>
<website>http://example.com/</website>
</user>
</users>
*/

json_encode() example for comparison:
PHP
 
header('Content-type: application/json');
echo json_encode($data);
 
/*
{
"users":[
{
"name":"user0",
"img":"http:\/\/example.com\/user0.png",
"website":"http:\/\/example.com\/"
},
{
"name":"user1",
"img":"http:\/\/example.com\/user1.png",
"website":"http:\/\/example.com\/"
},
{
"name":"user2",
"img":"http:\/\/example.com\/user2.png",
"website":"http:\/\/example.com\/"
}
]
}
*/

NOTE: for objects use something like:
PHP
 
if(is_object($data)){
$data=get_object_vars($data);
}

recursively diff two directories and exclude folders; SVN diff

This will exclude the .svn folders when diffing two directories.
Code
 
diff --exclude=".svn" -rq ~/mounts/www.example.com/ /var/www/www.example.com/
 

Run Multiple Regedit Windows; regedit.exe -m

This will allow you to run multiple instances of the Registry Editor (regedit.exe).
Code
Start > Run > regedit.exe -m
 

iPhone CSS overflow, overflow-x, overflow-y support

The iPhone and iPod Touch support overflow, but no scroll bars will appear. Use two fingers to scroll within the overflowed area.

CSS
.mydiv {
    overflow-x: auto;
}
Test the scrolling:
Code
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vel nulla justo. Vivamus pharetra dapibus tellus, nec faucibus massa ultrices a. Etiam imperdiet eros nunc. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi egestas sollicitudin varius. Vestibulum nec sapien sed ante gravida consequat. Phasellus id justo nunc. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla ultricies malesuada metus. Curabitur tempus, magna at tempus hendrerit, sem ante vehicula sapien, in adipiscing massa ligula quis diam. Praesent convallis elit nec ligula pharetra semper. Integer iaculis placerat lacus. Sed lobortis blandit turpis et blandit. Duis eu faucibus massa. Vestibulum a turpis in eros feugiat accumsan id nec purus. Nullam est magna, vehicula congue dictum eget, egestas ut ante. Donec molestie vehicula lacus eget fermentum.
 
Fusce dignissim consequat pulvinar. Nullam molestie nibh ac metus ullamcorper vel ullamcorper ante mattis. Integer quam neque, auctor non commodo et, mollis non ante. Duis tellus leo, tincidunt a lobortis id, vulputate eu dolor. Vivamus nec turpis eros. Curabitur tempus vulputate tortor sed cursus. Nullam aliquam, velit in posuere pellentesque, massa est vulputate turpis, a placerat nunc nisl non dui. Duis justo erat, adipiscing ut ultricies non, ornare vitae ante. In blandit lacinia ligula, vel auctor enim consectetur eget. Praesent adipiscing dolor varius enim bibendum non viverra est ultrices. Cras a tempus mi. Curabitur leo purus, lacinia quis sodales sit amet, euismod ac purus.
 
Etiam ut magna ut dolor semper laoreet sed et erat. Ut eget risus mauris. Phasellus imperdiet scelerisque massa, at gravida libero imperdiet sed. Duis interdum malesuada ante, non tincidunt velit semper pellentesque. Donec bibendum massa non sapien adipiscing luctus tempus urna imperdiet. Etiam at dignissim diam. Suspendisse potenti. Nunc vestibulum sagittis leo. Ut ornare, ligula id luctus dapibus, urna enim dignissim ante, a consequat arcu odio ac metus. Nunc pulvinar elit lectus. Proin fermentum ullamcorper tristique. Vivamus eu scelerisque purus. Nulla viverra consequat volutpat. Nulla lacus eros, tincidunt sed consectetur ac, luctus ac leo. Phasellus feugiat suscipit nisi vitae tempor. Cras non sapien vel metus auctor fringilla. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed pretium, augue at mollis bibendum, mi nunc molestie metus, ut laoreet ante est ut nisl. Maecenas vitae interdum est.
 
Vestibulum massa nisi, tempus non viverra sed, dignissim non tellus. Vivamus eu nisi at justo imperdiet dapibus. Sed metus mi, bibendum sit amet dictum sit amet, elementum sit amet orci. Phasellus scelerisque, leo sed varius varius, lectus lectus tincidunt neque, quis adipiscing nisi dui non elit. Cras lectus arcu, dictum ut volutpat euismod, dictum quis diam. Proin sit amet massa id ligula placerat ultricies. Praesent lorem elit, venenatis eget lobortis at, aliquet et nisl. Vestibulum rhoncus, dui at venenatis adipiscing, eros libero ornare elit, id feugiat tellus turpis vitae nunc. Proin egestas fringilla purus ac euismod. Nulla pharetra lorem ac dui auctor condimentum. Proin id leo eu quam euismod convallis. Aenean congue sapien ut nibh porta facilisis vitae a leo. Nullam mattis felis vitae nisi auctor aliquet. Nulla sed felis vitae nisl tempor congue. Maecenas ultrices, arcu in volutpat volutpat, nisi neque vestibulum tellus, ac lacinia quam metus nec tortor.
 
Fusce consectetur varius semper. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper, enim aliquet convallis aliquam, nulla lectus elementum risus, ut feugiat sapien est at sem. Pellentesque eget lorem eget urna blandit vestibulum nec nec ante. Phasellus ornare molestie nunc, id posuere lectus dignissim sed. Praesent mollis neque elit, eget rhoncus mi. Nullam diam libero, dapibus sit amet feugiat at, porttitor et nibh. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Etiam laoreet consectetur nibh id porttitor. Donec ornare eros at est pulvinar rhoncus. Suspendisse imperdiet, sem ornare cursus vestibulum, justo magna tincidunt elit, ac porta neque nunc eget nunc. Ut vitae erat vel tellus semper accumsan vitae non quam. Ut tempus tristique interdum. Cras a turpis ac velit ornare luctus nec et mauris. Duis ut nibh sem, ut imperdiet augue. Suspendisse sit amet lacus at tellus sagittis malesuada. Maecenas vel orci nec velit pretium convallis. Duis ornare pulvinar ipsum, vitae rutrum nisl blandit non.
 
Aenean eget iaculis lectus. Sed sollicitudin enim ut lorem imperdiet vel feugiat eros commodo. Fusce eget eros libero, ac pretium risus. Aenean volutpat scelerisque leo, et consectetur augue vehicula quis. In hac habitasse platea dictumst. Aenean dignissim sollicitudin porta. Integer semper, nunc et interdum gravida, lectus ante elementum orci, sed convallis ante dui eget massa. Quisque consectetur quam erat, non laoreet purus. Aliquam mauris nisl, egestas eget congue non, accumsan a nibh. Nulla libero erat, ornare ut auctor sed, tincidunt eget lorem.
 

Toggle Firefox Toolbars; Webdeveloper Toolbar; KeyConfig

Javascript
 
// Toggle the Bookmarks toolbar
var toolbar=document.getElementById('PersonalToolbar');
toolbar.collapsed=!toolbar.collapsed;
 
// Toggle the Web Developer toolbar
// see web_developer.xpi/chrome/webdeveloper.jar/content/webdeveloper/webdeveloper.js
var toolbar=document.getElementById('webdeveloper-toolbar');
toolbar.collapsed=!toolbar.collapsed;

Toggle Firefox Bookmarks Toolbar; KeyConfig

Toggle Firefox Bookmarks Toolbar
Install KeyConfig: http://mozilla.dorando.at/keyconfig.xpi
1. Go to Tools > KeyConfig.
2. [Add a new key]
3. Name: Toggle Firefox Bookmarks Toolbar
4. Code:
Javascript
 
// Toggle Firefox Bookmarks Toolbar
var b=document.getElementById('PersonalToolbar');
b.collapsed=!b.collapsed;

5. Click OK. Type a shortcut (CTRL+B) into the text box. Apply. Close. Open new window for changes.

PHP Normalize Newlines/Line Endings; CRLF; CR; LF; UNIX, Windows, Mac

PHP
 
define('CR', "\r"); // carriage return; Mac
define('LF', "\n"); // line feed; Unix
define('CRLF', "\r\n"); // carriage return and line feed; Windows
define('BR', '<br />' . LF); // HTML Break

PHP
 
function normalize($s) {
// Normalize line endings using Global
// Convert all line-endings to UNIX format
$s = str_replace(CRLF, LF, $s);
$s = str_replace(CR, LF, $s);
// Don't allow out-of-control blank lines
$s = preg_replace("/\n{2,}/", LF . LF, $s);
return $s;
}

PHP
 
function normalize($s) {
// Normalize line endings
// Convert all line-endings to UNIX format
$s = str_replace("\r\n", "\n", $s);
$s = str_replace("\r", "\n", $s);
// Don't allow out-of-control blank lines
$s = preg_replace("/\n{2,}/", "\n\n", $s);
return $s;
}

PHP Line Endings; CRLF; CR; LF; Newline; Linebreaks

PHP
 
define('CR',"\r"); // Carriage Return; UNIX
define('LF',"\n"); // Line Feed; Windows
define('CRLF',"\r\n"); // Carriage Return and Line Feed; Mac
define('BR','
'
.LF); // HTML Break

Remote Scripting with JSONP and jQuery

Using JSONP allows cross-domain HTTP GET requests.
The following code uses jQuery to call the Flickr API for a list of photos returned in JSON.
XML
 
<div id="photos"></div>

Javascript
 
$.ajax({
type:'GET',
url:'http://api.flickr.com/services/feeds/photos_public.gne?format=json&jsoncallback=?',
dataType:'jsonp',
success:function(data){
$.each(data.items, function(i,item){
$('<img/>').attr('src', item.media.m).appendTo('#photos');
});
}
});

NOTE: Updating is also possible (typically via POST) using a GET request, but limited to around 2000 characters for some browsers.

Ubuntu Firefox Default View Source Editor; view_source.editor.external; view_source.editor.path

To set the default view source editor in Ubuntu, do the following:
Code
 
// Firefox > about:config
view_source.editor.external=true;
view_source.editor.path=/usr/bin/scite;
 

PHP File Upload using cURL; Uploading a file using cURL just like a form POST

Upload a file using PHP and cURL.

PHP
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER => true);  // return web page string
curl_setopt($ch, CURLOPT_HEADER => false);         // don't return headers
curl_setopt($ch, CURLOPT_FOLLOWLOCATION => false); // follow redirects
curl_setopt($ch, CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1/upload.php');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array( 'image' => '@' . getcwd() . '/image.jpg',));
echo curl_exec($ch);

PHP File Upload Error Codes; UPLOAD_ERR_OK

PHP File Upload Error Codes
PHP
 
// UPLOAD_ERR_OK Value: 0; There is no error, the file uploaded with success.
// UPLOAD_ERR_INI_SIZE Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
// UPLOAD_ERR_FORM_SIZE Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
// UPLOAD_ERR_PARTIAL Value: 3; The uploaded file was only partially uploaded.
// UPLOAD_ERR_NO_FILE Value: 4; No file was uploaded.
// UPLOAD_ERR_NO_TMP_DIR Value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.
// UPLOAD_ERR_CANT_WRITE Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0.
// UPLOAD_ERR_EXTENSION Value: 8; File upload stopped by extension. Introduced in PHP 5.2.0.

PHP
 
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
 
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_FILES['myfile']['name'];
$type = $_FILES['myfile']['type'];
$tmp_name = $_FILES['myfile']['tmp_name'];
$error = $_FILES['myfile']['error'];
$size = $_FILES['myfile']['size'];
 
switch ($error) {
case UPLOAD_ERR_OK:
$response = 'There is no error, the file uploaded with success.';
break;
case UPLOAD_ERR_INI_SIZE:
$response = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';
break;
case UPLOAD_ERR_FORM_SIZE:
$response = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';
break;
case UPLOAD_ERR_PARTIAL:
$response = 'The uploaded file was only partially uploaded.';
break;
case UPLOAD_ERR_NO_FILE:
$response = 'No file was uploaded.';
break;
case UPLOAD_ERR_NO_TMP_DIR:
$response = 'Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.';
break;
case UPLOAD_ERR_CANT_WRITE:
$response = 'Failed to write file to disk. Introduced in PHP 5.1.0.';
break;
case UPLOAD_ERR_EXTENSION:
$response = 'File upload stopped by extension. Introduced in PHP 5.2.0.';
break;
default:
$response = 'Unknown error';
break;
}
 
echo $response;
}
else {
echo
'<form action="upload.php" enctype="multipart/form-data" method="post">' .
'<input name="myfile" type="file" /><br />' .
'<input type="submit" value="Submit" />' .
'</form>' .
'';
}