我正在使用模型-视图-控制器结构开发一个网站。在我的 html 中,我有一个表单,允许用户浏览和选择文件,然后通过单击按钮提交文件,然后调用控制器代码:
if(upload_quotes($_FILES['userfile'])){
$msg = "Successful file upload";
$directory_list = array();
// get contents of directory here
// $directory_list = get_directory_contents($directory_list);
include '../view/processFileUpload.php';
}else{
$msg = "Unknown error occurred. Error: ".print_r($_FILES);
include '../view/errorPage.php';
}
第一行:upload_quotes() 是位于模型代码中的函数。如果上传成功,该函数返回 true,如果不成功,则返回 false。我已经注释掉了获取目录列表的函数调用,因为它也有错误。2个模型代码片段:
function upload_quotes($_FILES){
$uploadfile = '../../../TestSiteDataFiles/Quotes/'.$_FILES['userfile']['name'];
if(move_uploaded_file($_FILES['tmp_name'], $uploadfile)){
return true;
}else{
return false;
}
}
function get_directory_contents($directory_list){
$current_dir = '../../../TestSiteDataFiles/Quotes/';
$dir = opendir($current_dir);
//reads and outputs the directory
while(false !== ($file = readdir($dir)))
//strip out the two entries of . and ..
if($file != "." && $file !=".."){
array_push($directory_list, $file);
}
closedir($dir);
return $directory_list;
}
processFileUpload.php 和 errorPage.php 文件相应地输出 $msg 变量,但它从不输出成功。我花了几个小时研究我做错了什么,而我对 php 的有限知识没有任何帮助。查看页面输出“发生未知错误。错误:1。浏览器上弹出的错误是:
警告:move_uploaded_file() [function.move-uploaded-file]:copy() 函数的第二个参数不能是第 17 行 C:\xampp\htdocs\Test Site\model\model.php 中的目录
警告:move_uploaded_file() [function.move-uploaded-file]:无法将 'C:\xampp\tmp\php487A.tmp' 移动到 C:\ 中的 '../../../TestSiteDataFiles/Images/' xampp\htdocs\Test Site\model\model.php on line 17 Array ([name] => Managerial Accounting Davers Connect.txt [type] => text/plain [tmp_name] => C:\xampp\tmp\php487A. tmp [错误] => 0 [大小] => 55 )
在我看来,模型代码 ( upload_quotes()
) 是错误的根源,因为它每次都返回为 false。该get_directory_contents()
函数永远不会有机会执行,但它也不会输出正确的结果。
我感谢任何和所有建议,并感谢您的投入。