我自己加了个很简单的判断,但是不对,文件上传不了了,也没错误提示
在线等,谢谢!
code:
======================================
<?php
include ('../header.php');
include ('../secure_page.php');
include ('../php/phpClass/data_class.php');
$userID=$_SESSION['user_id'];
$user=$_SESSION['username'];
$dest_dir="../media/$user/".date(Ymd);
if( !is_dir($dest_dir) || !is_writeable($dest_dir) )
{
if(!mkdir($dest_dir, 0777, true))
die("The expected directory ".$dest_dir." encountered errors");
}
$type=array("png","jpg","jpeg");
$upfile=$_FILES['file'];
if($upfile != NULL)
{
function fileext($filename)
{
return substr(strrchr($filename, '.'), 1);
}
if( !in_array( strtolower( fileext($upfile['name'] ) ),$type) )
{
$text=implode(",",$type);
echo "Sorry, you cannot upload this file type: ",$text;
}
else
{
$dest=$dest_dir.'/'.date("His")."_".$upfile['name'];
$state=move_uploaded_file($upfile['tmp_name'],$dest);
if ($state)
{
print("File Uploaded. Thanks for your contribution!");
}
else
{
switch($upfile['error'])
{
case 1 : die("File size is larger than php.ini: upload_max_filesize");
case 2 : die("File is too large");
case 3 : die("Only part of file has been uploaded");
case 4 : die("No file has been uploaded");
case 5 : die("Cannot find the expected directory");
case 6 : die("File cannot be written");
}
}
}
}
else
{
print("Thanks for your contribution!");
}
$aname = $_POST['aname'];
$atime = $_POST['atime'];
$adate = $_POST['adate'];
$latitude = $_POST['latitude'];
$longitude = $_POST['longitude'];
$agchoice = $_POST['agchoice'];
$age = $_POST['age'];
$aschoice = $_POST['aschoice'];
$adescription = $_POST['adescription'];
$dataClass = new Data();
$data = array($aname,$atime,$adate,$latitude,$longitude,$agchoice,$aschoice,$adescription,$age,$dest);
$h = $dataClass->add_sighting($data, $userID);
?>
==========================