Index.html
Copy the Code code as follows:
No refresh upload file
upload.php
Copy the Code code as follows:
Sleep (2);
$fileTypes = array (' jpg ', ' png ', ' gif ', ' bmp ');
$result = null;
$uploadDir = './upfiles ';
$maxSize = 1 * POW (2,20);
if ($_server[' request_method ') = = ' POST ' && isset ($_post[' Sub ')) {
$myfile = $_files[' myfile ');
$myfileType = substr ($myfile [' name '], Strrpos ($myfile [' name '], ".") + 1);
if ($myfile [' Size '] > $maxSize) {
$result = 1;
} else if (!in_array ($myfileType, $fileTypes)) {
$result = 2;
} elseif (Is_uploaded_file ($myfile [' tmp_name '])) {
$toFile = $uploadDir. '/' . $myfile [' name '];
if (@move_uploaded_file ($myfile [' Tmp_name '], $toFile)) {
$result = 0;
} else {
$result =-1;
}
} else {
$result = 1;
}
}
?>
The above is introduced in the five-year language courseware PHP no refresh upload file implementation code, including the five-year Chinese courseware content, I hope that the PHP tutorial interested in a friend helpful.