对于上传,我想检查年文件夹和月子文件夹是否已经存在。如果他们不这样做,我想创建它们并将我的上传保存在那里。
<?php
$newname = $_POST['changename'];
$temp = explode(".", $_FILES["uploadfile"]["name"]);
$extension = end($temp);
if(!(
$_FILES['uploadfile']['type']=='image/jpeg' ||
$_FILES['uploadfile']['type']=='image/png' ||
$_FILES['uploadfile']['type']=='image/gif' ||
$_FILES['uploadfile']['type']=='image/bmp'
)) // if file does not equal these types, kill it
{
echo $_FILES['uploadfile']['type'] . " is not an acceptable format.";
die();
}
if ($_FILES["uploadfile"]["size"] > 20000000)
{
echo "File too big. Max 20mb";
die();
}
if ($_FILES["uploadfile"]["error"] > 0)
{
echo "Return Code: " . $_FILES["uploadfile"]["error"] . "<br>";
}
else
{
$new_file_name = $newname.".".$extension;
$path = "uploads/".$new_file_name;
move_uploaded_file($_FILES["uploadfile"]["tmp_name"],$path);
echo json_encode(array(
"success" => true,
"imagepath" => $path,
"filetype" => $_FILES["uploadfile"]["type"],
"new_file_name" => $newname,
"fileName" => $_FILES["uploadfile"]["name"],
"fileTmp" => $_FILES["uploadfile"]["tmp_name"],
));
}
?>