【发布时间】:2014-11-25 10:34:07
【问题描述】:
在我的应用程序中,我想将同一个文件保存在两个不同的目录中。在我的 www 文件夹中,我有两个名为 folder1 和 folder2 的文件夹。我将图像上传到文件夹 1 中的“上传”目录。我想将此图像移动到位于文件夹 2 内的名为“上传”的文件夹中。
这是我的代码。
$target = "uploads/";
$target = $target . basename( $_FILES['photo']['name']);
$target2="folder2/uploads/";
//This gets all the other information from the form
$desc=$_POST['desc'];
$pic=($_FILES['photo']['name']);
$loc=$_POST['location'];
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("selfie") or die(mysql_error()) ;
$filename = mysql_real_escape_string($_FILES['photo']['name']);
//Writes the information to the database
mysql_query("INSERT INTO image_upload (description,image,location) VALUES ('$desc','$pic','$loc')");
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
copy($target, $target2);
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
我使用了“复制()”。作为一个新的网络开发人员,我不知道它是否正确。我的upload.php 位于folder1 中。谁能帮帮我。
【问题讨论】: