PHP在AJAX功能中移动图像



我一直在触发AJAX功能,我的部分功能是

private function saveImageOfThePlace()
{
$image_name = $this->json['order']['image_temp']; // phpBDobOY
$ext  = $this->json['order']['ext'];              // jpg
$full_path = 'wp-content/plugins/WindProofCurtainsCalculator/Temp/'.$image_name.'.'.$ext;
$new_path  = 'wp-content/plugins/WindProofCurtainsCalculator/uploaded_images/'.$image_name.'.'.$ext;
if ( file_exists($full_path) ) {
//copy($full_path, $new_path);
unlink($full_path);
}

// move_uploaded_file($_FILES['image']['tmp_name'], plugin_dir_path( dirname( __FILE__, 2 )).$this->json['order']['image']);
return $this;
}

我可以看到其他一切都工作正常,但只有我被困在这一部分。我想移动图像到另一个文件夹,如果有人可以帮助我将非常感谢!

我尝试了您的代码在我的本地主机。如果文件存在,它会将文件uploads移动到uploaded_images目录。此外,如果复制失败,它也不会删除原始文件。

$file_destination = 'wp-content/uploads/007-team-work 1-min.png';
$file_destination_new = 'wp-content/uploads/uploaded_images/007-team-work 1-min.png';
if( file_exists($file_destination) ) {
if(copy($file_destination, $file_destination_new)) {
unlink($file_destination);
}
}

确保你的数据是正确的,尝试调试。确保$full_path$new_path文件夹存在。

最新更新