将图像上传到服务器中的两个不同文件夹 [英] upload images to two different folders in server

查看:45
本文介绍了将图像上传到服务器中的两个不同文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Wamp 服务器中,我有文件夹调用自拍.upload.php 位于此文件夹中.当我上传图像时,此图像保存在自拍文件夹内的上传"文件夹中.同时,我的 wamp 服务器中有另一个名为admin"的文件夹.它还包含文件夹调用上传"

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.

这是我的upload.php,它位于'selfie'文件夹内.

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."; 
 } 
  ?>

谁能帮帮我..

推荐答案

我看到您使用的是相对路径,请尝试使用绝对路径.

I see you are using relative paths, try absolute.

这篇关于将图像上传到服务器中的两个不同文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆