简体   繁体   English

将图像上传到服务器中的两个不同文件夹

[英]upload images to two different folders in server

In my Wamp server I have folder call selfie. 在我的Wamp服务器中,我有文件夹呼叫自拍照。 upload.php located within this folder. 位于此文件夹中的upload.php。 When I upload an image this image save inside the 'uploads' folder which is inside the selfie folder. 当我上传图像时,此图像保存在selfie文件夹内的“ uploads”文件夹中。 At the same time I have another folder call 'admin' inside my wamp server. 同时,我的wamp服务器中还有一个名为“ admin”的文件夹。 It also contain folder call 'uploads' 它还包含文件夹调用“上载”

What I want is save same image to both 'uploads' folders. 我想要的是将相同的图像保存到两个“上传”文件夹中。 I used 'copy'. 我使用了“复制”。 But it's not work. 但这是行不通的。

Here is my upload.php which is located inside the 'selfie' folder. 这是我的upload.php,它位于“ selfie”文件夹中。

        <?php 

//This is the directory where images will be saved 
$target = "uploads/"; 
$target = $target . basename( $_FILES['photo']['name']); 
$target2="admin/uploads/";
$target2 = $target2 . basename( $_FILES['photo']['name']);

 //This gets all the other information from the form 
  $cat=$_POST['cat']; 
  $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 (category, description,image ,location)     VALUES     ('$cat', '$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."; 
 } 
  ?>

Can anyone help me.. 谁能帮我..

我看到您正在使用相对路径,请尝试绝对路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM