drktvjp713333 2016-09-08 21:12 采纳率: 0%
浏览 29
已采纳

将同一图像上载到两个不同的目录

I want to upload the same image to two different directory but it only uploads to the first directory called upload/. I have also tried copy command but cannot get the file to be uploaded to the second directory called photo/. How can I accomplish that?

<?php

$uname=strip_tags($_POST['uname']);

//$uname='user1';
$session_uid='user1';

$path='upload/';
$path1='photo/';


include_once 'background.php';

$valid_formats = array("jpg", "png", "gif", "bmp","jpeg","PNG","JPG","JPEG","GIF","BMP");
if(isset($_POST) && $_SERVER['REQUEST_METHOD'] == "POST" && isset($session_uid))
{
$name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];


if(strlen($name))
{
$ext = getExtension($name);
if(in_array($ext,$valid_formats))
{
if($size<(1024*1024))
{

$actual_image_name = time().$session_uid.".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
$bgSave='<div id="uX'.$session_uid.'" class="bgSave wallbutton blackButton">Image Saved</div>';
if(move_uploaded_file($tmp, $path.$actual_image_name)){

echo $bgSave.'<img src="http://localhost/testing/'.$path.$actual_image_name.'"  id="timelineBGload" class="headerimage ui-corner-all" style="top:0px"/>';

}

// try upload to the second directyory 
if(!copy ($path, $path1.$actual_image_name)){
throw new Exception('Could not move 2nd file');
exit();
}


else
{
echo "Fail upload folder with read access.";
}
}
else
echo "Image file size max 1 MB";
}
else
echo "Invalid file format.";
}

else
echo "Please select image..!";

exit;
}
?>
  • 写回答

1条回答 默认 最新

  • dsn46282 2016-09-08 21:27
    关注

    Just like you did in move_uploaded_file(), you need to give the full source path to the file. $tmp = $_FILES['photoimg']['tmp_name'] is the full path to the source temp file. So after the move you need to give the full source path using $path and $actual_image_name:

    if(!copy($path.$actual_image_name, $path1.$actual_image_name)){
        throw new Exception('Could not move 2nd file');
        exit();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误