duanbu9345 2016-03-14 08:46
浏览 58

将视频上传到PHP中的特定文件夹

So i have an Android app that uploads a selected video to my server. The video right now gets uploaded fine but it doesnt get placed to the new directory that is created when i upload the video. Even though i think the location is wrong right now in the move_uploaded_file it still uploads to the ProductVideos.

I want it to create a new directory and then store the video there. (new directory has 777 permissions even though its bad i know and new directory is created in /var/www/html/ProductVideos/)

PHP code:

<?php

if($_SERVER['REQUEST_METHOD']=='POST'){
$file_name = $_FILES['myFile']['name'];
$file_size = $_FILES['myFile']['size'];
$file_type = $_FILES['myFile']['type'];
$temp_name = $_FILES['myFile']['tmp_name'];


    $ProductAccountName = $_POST['ProductAccountName'];
    $ProductName = $_POST['ProductName'];

    $NewDirectory = "/var/www/html/ProductVideos/" . $ProductAccountName;
    mkdir($NewDirectory, 0777, true);


    $conn = mysqli_connect("XXXXXX", "XXXXXX", "XXXXXX", "Products");

    $sql_query = "select Product_Name from Product_Details where Product_Name like '$ProductName';";

    $result = mysqli_query($conn, $sql_query);

    if(mysqli_num_rows($result) > 0 ){
    $statement = mysqli_prepare($conn, "UPDATE Product_Details SET 7sec_File_Path = ? WHERE Product_Name = '$ProductName'");

    $FileLocation = $NewDirectory."/".$ProductName;

    mysqli_stmt_bind_param($statement, "s", $FileLocation);
    mysqli_stmt_execute($statement);
    mysqli_stmt_close($statement);
    }
    mysqli_close($conn);



 $location = "/var/www/html/ProductVideos/".$ProductAccountName."/";
 move_uploaded_file($temp_name, $location.$file_name);
 //move_uploaded_file($location.$file_name,       "/var/www/html/ProductVideos/".$ProductAccountName."/");
 echo   "Uploaded!";
 }else{
 echo "Error";
 }
?>
  • 写回答

1条回答 默认 最新

  • doulian8554 2016-03-14 09:03
    关注

    Try this...

    <?php
        if($_SERVER['REQUEST_METHOD']=='POST')
        {
            if (isset($_FILES['myFile']))
            {
                $file_name = $_FILES['myFile']['name'];
                $file_size = $_FILES['myFile']['size'];
                $file_type = $_FILES['myFile']['type'];
                $temp_name = $_FILES['myFile']['tmp_name'];
            }
    
            $ProductAccountName = isset($_POST['ProductAccountName'])?$_POST['ProductAccountName']:rand();
            $ProductName = isset($_POST['ProductName']):$_POST['ProductName']:rand();
    
            $NewDirectory = "/var/www/html/ProductVideos/" . $ProductAccountName;
            if (!file_exists($NewDirectory)) 
            {
                mkdir($NewDirectory, 0777, true);
            }
    
            $conn = mysqli_connect("XXXXXX", "XXXXXX", "XXXXXX", "Products");
    
            $sql_query = "select Product_Name from Product_Details where Product_Name like '$ProductName';";
    
            $result = mysqli_query($conn, $sql_query);
    
            if(mysqli_num_rows($result) > 0 )
            {
                $statement = mysqli_prepare($conn, "UPDATE Product_Details SET 7sec_File_Path = ? WHERE Product_Name = ?");
    
                $FileLocation = $NewDirectory."/".$ProductName;
    
                mysqli_stmt_bind_param($statement, "s", $FileLocation,$ProductName);
                mysqli_stmt_execute($statement);
                mysqli_stmt_close($statement);
            }
            mysqli_close($conn);
    
            move_uploaded_file($temp_name, $NewDirectory.$file_name);
            //move_uploaded_file($location.$file_name,       "/var/www/html/ProductVideos/".$ProductAccountName."/");
            echo   "Uploaded!";
         }
         else
         {
            echo "Error";
         }
    ?>
    

    Hope it will work for you.

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?