Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
947 views
in Technique[技术] by (71.8m points)

php - upload images to two different folders in server

In my Wamp server I have folder call selfie. upload.php located within this folder. When I upload an image this image save inside the 'uploads' folder which is inside the selfie folder. At the same time I have another folder call 'admin' inside my wamp server. 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.

        <?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..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I see you are using relative paths, try absolute.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...