drhg24275 2015-05-21 09:08
浏览 33
已采纳

使用一个IF-Statement中的变量到PHP中的另一个IF语句

I have a variable $target inside an IF - Statement in my login.php. I created the folders and sub-folders based on this variable. Now i want to move the uploaded file to this location. How can I do that?

here is the code

$upload = "E:/demons";

if(isset($_POST['userid'], $_POST['pid']))
         {
         $userid = trim($_POST["userid"]);
         $pid = trim($_POST["pid"]);

         $sql = "SELECT * FROM template WHERE uname = '$userid' and pword = '$pid'";
         $result = mysqli_query($conn,$sql);
         $row = mysqli_fetch_array($result);  



        echo "公司".'<br/>';
        echo $row['client'].'<br/>'.'<br/>';
        echo "第".'<br/>';
        echo '<a href="upload.html"/>'.$row['day1'].'</a>'.'<br/>';


        $target = $upload.'/'.$row['week'].'/'.$row['day1'].'/'.$row['client'].'/'.$row['brand'].'/'.$row['sc'].'/';


        $imagename = $row['week'].'.'.$row['day1'].'.'.$row['client'].'.'.$row['brand'].'.'.$row['sc'].'.'.'jpg';


                if(!file_exists($target))
                    {
                        mkdir($target,null,true);
                    }
        }

else if(isset($_FILES['image']))
        {
        $image = basename($_FILES["image"]["name"]);
        echo $image;
        //$target4 = $upload.'/'.$row['week'].'/'.$row['day1'].'/'.$row['client'].'/'.$row['brand'].'/'.$row['sc'].'/';
        move_uploaded_file($_FILES['image']['tmp_name'], $target);
        }
        else
            {
                echo "asdfg";
         } 

Userid and Pid comes from login.html and Image value comes from upload.html

  • 写回答

2条回答 默认 最新

  • dongzhuner6981 2015-05-22 07:51
    关注
    $upload = "Your desired location";
    
    
    //comes from the login.html page
    if(isset($_POST['userid'],$_POST['pid']))
    {
      $userid = trim($_POST["userid"]);
      $pid = trim($_POST["pid"]);
    
      $sql = "SELECT * FROM template WHERE uname = '$userid' and pword = '$pid'";
      $result = mysqli_query($conn,$sql);
      $row = mysqli_fetch_array($result);
    
      echo "Whatever coloumn you wish to echo from database".'<br/>';
      echo $row['col1'].'<br/>'.'<br/>';
      echo "Second Coloumn".'<br/>';
      echo '<a href="upload.html"/>'.$row['col2'].'</a>'.'<br/>';
    //create the folders and subfolders based on the data from the database
    $target = $upload.'/'.$row['col1'].'/'.$row['col2'].'/'.$row['col3'].'/'.$row['col4'].'/'.$row['col5'].'/';
    
    //for renaming the image.
    $imagename = $row['col1'].'.'.$row['col2'].'.'.$row['col3'].'.'.$row['col4'].'.'.$row['col5'].'.'.'jpg';
    //create the folders and subfolders
     if(!file_exists($target))
       {
         mkdir($target,null,0777);
       }
    //start session and store the value of $target and $imagename in a variable 
    session_start();
    $_SESSION['str'] = $target;
    $_SESSION['img'] = $imagename;
    
    //This comes from other HTML page but to the same PHP.
    if(isset($_FILES['image']))
    
    // image upload from upload.html 
    // Want the value of target here.
      {
    
          session_start();
          $_SESSION['str'];
          $_SESSION['img'];
          $image = basename($_FILES["image"]["name"]);
    
    //Move the uploaded file to the desired location.
     move_uploaded_file($_FILES['image']['tmp_name'], $_SESSION['str'].$_SESSION['img']);
    
    echo "Upload Successful";
    

    Hope this would be helpful for all.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度