更新 index.php
兼容5.0代码加入。
This commit is contained in:
parent
a18b433cc6
commit
c83a456cac
@ -16,7 +16,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
|
||||
|
||||
// 兼容跨平台路径
|
||||
$md5 = md5_file($file_tmp);
|
||||
$upload_dir = __DIR__ . $base_dir . substr($md5,0,1).'/'.substr($md5,1,1);
|
||||
$upload_dir = getcwd() . $base_dir . substr($md5,0,1).'/'.substr($md5,1,1);
|
||||
// 检查并创建目录
|
||||
if (!is_dir($upload_dir)) {
|
||||
if (!mkdir($upload_dir, 0777, true) && !is_dir($upload_dir)) {
|
||||
@ -25,13 +25,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
|
||||
}
|
||||
// 开始创建index.html
|
||||
file_put_contents($upload_dir .'/index.html', 'no access');
|
||||
file_put_contents( __DIR__ . $base_dir . substr($md5,0,1). '/index.html', 'no access');
|
||||
file_put_contents( getcwd() . $base_dir . substr($md5,0,1). '/index.html', 'no access');
|
||||
}
|
||||
|
||||
// 根据文件内容生成MD5文件名,这样可以排除重复上传
|
||||
$FileName = md5_file($file_tmp). '.' . strtolower(pathinfo($name, PATHINFO_EXTENSION));
|
||||
// 这里判断下重复文件不移动文件
|
||||
if (file_exists($target_file) || move_uploaded_file($file_tmp, $upload_dir . '/' .$FileName)) {
|
||||
$target_file=$upload_dir . '/' .$FileName;
|
||||
if (file_exists($target_file) || move_uploaded_file($file_tmp, $target_file)) {
|
||||
echo '{"upload_url":"http://'.$_SERVER['HTTP_HOST'] . $base_dir . substr($md5,0,1). '/' .substr($md5,1,1) .'/'. $FileName.'"}';
|
||||
} else {
|
||||
echo '{"error":"写入失败,无法保存文件"}';
|
||||
|
Loading…
x
Reference in New Issue
Block a user