在我的應用程序中,我想將相同的文件保存在兩個不同的目錄中。在我的www文件夾中,我有兩個文件夾調用folder1和folder2。我將圖像上傳到folder1中的「上傳」目錄。我想將此圖像移至位於folder2內的名爲'uploads'的文件夾。上傳到多個目錄
這是我的代碼。
$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.";
}
?>
我用'copy()'。作爲一名新的Web開發人員,我不知道它是否正確。我的upload.php位於folder1中,任何人都可以幫助我。
我試過了。但這不起作用。我不知道賦予target2的語法是否正確。 – Lanka 2014-11-25 10:44:25
檢查文件結構。兩個文件夾的路徑級別應該相同。 – 2014-11-25 10:48:09