php中如何上传文件

来源:百度知道 编辑:UC知道 时间:2024/05/23 23:14:07
<?
$action=$_POST['action'];
if($action=="submit"){
$uploaddir = 'e:/source/test/php/temp/';
$uploadfile = $uploaddir . basename($_FILES['fileField']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['fileField']['tmp_name'], $uploadfile)) {
echo "上传成功.\n";
} else {
echo "上传失败!\n";
}
echo '更多详细信息:';
print_r($_FILES);
print "</pre>";
}
?>

请教一下如何将这段代码改成能同时上传两个图片,并且是只能上传.jpg或.gif的啊? 谢谢!

<?php
//process_upload.php
//Allowed file MIME types.
$allowedtypes = array ("image/jpeg","image/pjpeg","image/png","image/gif");
//Where we want to save the file to.
$savefolder = "images";
//If we have a valid file
if (isset ($_FILES['myfile'])){
//Then we need to confirm it is of a file type we want.
if (in_array ($_FILES['myfile']['type'], $allowedtypes)){
//Then we can perform the copy.
if ($_FILES['myfile']['error'] == 0){
$thefile = $savefolder . "/" . $_FILES['myfile']['name'];
if (!move_uploaded_file ($_FILES['myfile']['tmp_name'], $thefile)){
echo "There was an error uploading the file.";
} else {
//Signal the parent to load the image.
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"➥
"