为什么我在线上复制文件时会收到权限错误?
我在print_r
上有$candidatefile
,这显示了新位置的完整文件路径和正确名称。
$fields['Resume']
时 print_r
为空,但文件仍然上传到缓存
这两个文件夹都是777
/home/name/mysite0912/cache/resumes/1ZHiYGZj7J.txt Remuse /home/name/mysite0912/downloads/cv_folder/new-filename-cv.txt新位置
除了
之外,其他一切都很好代码部分:
$candidateuploaddir = _MYSITEDIR . '/downloads/refocus_candidates/';
$candiatefilename = $fields['RenamedResume'];
$candidatefile = $candidateuploaddir . $candiatefilename;
if(empty($fields['Resume']))
{
echo 'null';
}else{
copy($fields['Resume'],$candiatefilename);
}
上传功能
function uploadResume()
{
if (!isset($_FILES['UploadResume'])) return false;
$uploaddir = _CACHEDIR.'/resumes/';
/* create the upload folder if it does not already exist */
CMS::RecursiveMkdir($uploaddir);
$extension = CMS::getFileExtension(basename($_FILES['UploadResume']['name']));
/* keep producing random filenames until we get a unique one */
while (empty($filename) || CMS::fileExists($uploaddir.$filename)) {
$filename = CMS::randomString(10).'.'.$extension;
}
$uploadfile = $uploaddir . $filename;
if (move_uploaded_file($_FILES['UploadResume']['tmp_name'], $uploadfile)){
return $uploadfile;
//$uploadfile;
} else {
return false;
}
}
提交行
$fields['Resume'] = CMS::either(CMS_Plugin_plugin_jobs_apply::uploadResume(), CMS::getFormData('Resume', false)); //upload resume to temporary location
答案 0 :(得分:0)
所以我们是一个($ _FILES)的print_r;您是否设置了表单的enctype以允许上传文件?
在此行之前,添加:
copy($fields['Resume'],$candiatefilename);
file_exists($fields['Resume']) or die('can not copy file '.$fields['Resume'].' because it does not exist !');
// else
copy($fields['Resume'],$candiatefilename);