我正在尝试将3个文件从现有文件夹复制到刚刚使用mkdir创建的新文件夹。到目前为止没有运气。文件不会复制到文件夹中,PHP也报告没有错误。我使用PHP语法检查器在线检查了代码,它回来了。
我认为我的格式错误在复制命令中但我不确定具体问题是什么。我已经尝试在要复制的文件和目的地上使用没有引用和单引号,但都没有工作。我仔细检查了要复制的文件的网址,这是正确的。
任何建议都将不胜感激。
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
$index = null, $content_range = null) {
$file = new \stdClass();
$file->name = $this->get_file_name($uploaded_file, $name, $size, $type, $error,
$index, $content_range);
$file->size = $this->fix_integer_overflow((int)$size);
$file->type = $type;
if ($this->validate($uploaded_file, $file, $error, $index)) {
$this->handle_form_data($file, $index);
$upload_dir = $this->get_upload_path();
if (!is_dir($upload_dir)) {
mkdir($upload_dir, $this->options['mkdir_mode'], true);
//Attempting to add new code below
//let's secure the new folders with 3 copied files
$copy1 =copy(/files/.gitignore, '$upload_dir'.'/.gitignore');
$copy2 =copy(/files/.htaccess, '$upload_dir'.'/.htaccess');
$copy3 =copy(/files/index.html, '$upload_dir'.'/index.html');
}
$file_path = $this->get_upload_path($file->name);
$append_file = $content_range && is_file($file_path) &&
$file->size > $this->get_file_size($file_path);
if ($uploaded_file && is_uploaded_file($uploaded_file)) {
// multipart/formdata uploads (POST method uploads)
if ($append_file) {
file_put_contents(
$file_path,
fopen($uploaded_file, 'r'),
FILE_APPEND
);
} else {
move_uploaded_file($uploaded_file, $file_path);
}
} else {
// Non-multipart uploads (PUT method support)
file_put_contents(
$file_path,
fopen('php://input', 'r'),
$append_file ? FILE_APPEND : 0
);
}
$file_size = $this->get_file_size($file_path, $append_file);
if ($file_size === $file->size) {
$file->url = $this->get_download_url($file->name);
if ($this->is_valid_image_file($file_path)) {
$this->handle_image_file($file_path, $file);
}
} else {
$file->size = $file_size;
if (!$content_range && $this->options['discard_aborted_uploads']) {
unlink($file_path);
$file->error = $this->get_error_message('abort');
}
}
$this->set_additional_file_properties($file);
}
return $file;
}