我试图创建一个相当简单的(理论上)文件上传'进程'。我浏览了这个网站,虽然有我需要的片段,但似乎没有任何工作!文件上传/ mkdir()问题
基本上,我试图创建一个处理如下功能:
- 获取文件扩展
- 获取文件名
- 合并的文件名,clientID的和扩展
- 检查目标目录存在。如果没有,创建它。
- 文件(在新名称)移动到目录
我的文件结构如下:
- 根
- 管理
- 上传
- client_uploads
- $客户端ID
- client_uploads
- 上传
- 管理
这是我有:
<?php
include("dbconnect.php");
error_reporting(-1); // ALL messages and
ini_set('display_errors', 'On');
if($_GET['clientID']){
//This function separates the extension from the rest of the file name and returns it
function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}
//Get filename function
$filename = "test"; //I dont know how to create this function at the moment
return $filename;
//This applies the function to our file
$ext = findexts ($_FILES['uploaded']['name']) ;
// we will be using the clientID as the new folder and adding it into the filename
$clientID = mysql_real_escape_string((int)$_GET['clientID']);
//merge filename
$filename2 = $filename."_".$clientID.".";
//Scan for existing directory
$folder = '../admin/uploads/client_uploads/'.$username.'/';
if (is_dir("$folder") == false) {
mkdir("$folder", 0777);
echo "Directory created";
}
//This assigns the subdirectory you want to save into... make sure it exists!
$target = "admin/client_uploads/$clientID";
//This combines the directory, the random file name, and the extension
$target = $target . $filename2.$ext;
//Move file under new name
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file has been uploaded as ".$filename2.$ext;
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>
我没有收到任何错误消息(尽管我已经明确要求他们),我最终只是一个空白的屏幕。文件夹不是在我的服务器上的任何地方创建的,没有任何反应
任何想法?提前致谢。
你是否检查过PHP的错误日志中的消息?你是否试图通过注释掉部分和'var_dump'个别变量来逐步调试? – deceze
我不知道如何检查我的错误日志 - 我会以为我的第一行代码会在页面上显示任何错误? – Anthony
似乎也是'分裂'命令的错误 - 关于它的折旧。我需要使用'爆炸'cammond还是其他地方? – Anthony