SoFunction
Updated on 2025-03-10

Ajax+PHP Learn and Practice 5 Picture Processing


<?php
//Providing image type verification
$allowedtypes = array("image/jpeg","image/pjpeg","image/png", "image/x-png","image/gif");
//File storage directory
$savefolder = "images";

//If there is a file upload, start working
if (isset ($_FILES['myfile'])){
//Check whether the uploaded file complies with the $allowedtypes type
if (in_array($_FILES['myfile']['type'],$allowedtypes)){
if ($_FILES['myfile']['error'] == 0){
$thefile = "$savefolder/".$_FILES['myfile']['name'];
//Uploaded file via move_uploaded_file
if (!move_uploaded_file($_FILES['myfile']['tmp_name'], $thefile)){
echo "There was an error uploading the file.";
}
else{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http:///TR/xhtml1/DTD/">
<html xmlns="http:///1999/xhtml">
<head>
<script type="text/javascript" src=""></script>
</head>
<body>
<!-- Show picture -->
<img src="<?php echo $thefile; ?>" onload="doneloading(parent,'<?php echo $thefile; ?>')" />
</body>
</html>
<?php
}
}
}
}
?>