First the effect picture:
Create Form in
Sample6_1.php:
Copy code The code is as follows:
//Display upload status and pictures
//Uploading files requires defining enctype, In order to display the image, set the target to uploadframe
Upload image function uploadimg:
Copy code The code is as follows:
function uploadimg(theform){
/ /Submit Form
theform.submit();
//Show upload status in showimg
setStatus ("Loading...","showimg");
}
//Upload status function
function setStatus ( theStatus, theObj){
obj = document.getElementById(theObj);
if (obj){
obj.innerHTML = "
" + theStatus + "
";
}
}
process_upload.php provides file upload function:
Copy code The code is as follows:
//Provide image type verification
$allowedtypes = array("image/jpeg ","image/pjpeg","image/png", "image/x-png","image/gif");
//File storage directory
$savefolder = "images";
//If there are files uploaded Let’s start working
if (isset ($_FILES['myfile'])){
//Check whether the uploaded file matches the $allowedtypes type
if (in_array($_FILES['myfile']['type'],$allowedtypes )){
if ($_FILES['myfile']['error'] == 0){
$thefile = "$savefolder/".$_FILES['myfile']['name'];
//Pass move_uploaded_fileUpload file
if (!move_uploaded_file($_FILES['myfile']['tmp_name'], $thefile)){
echo "There was an error uploading the file.";
}
else{
?>
BR>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> ;