zoukankan      html  css  js  c++  java
  • ubuntu curl upload file to apache2 server

    ubuntu curl upload file to apache2 server

    1 install

    $ sudo apt-get install apache2
    $ sudo apt-get install php5
    $ sudo apt-get install libapache2-mod-php5
    $ sudo apt-get install php5-gd
    

    2 get web info

    $ cat /etc/apache2/sites-enabled/000-default.conf
    

    3 set php upload conditions

     

    3.2 upload_max_fileszie

    $ sudo nano /etc/php5/apache2/php.ini
    

    change `upload_max_fileszie = 2M' as upload_max_fileszie = 30M

    3.3 post_max_size

    $ sudo nano /etc/php5/apache2/php.ini
    

    change `post_max_size = 8M' as post_max_size = 30M

    3.4 max_execution_time cfg

    $ sudo nano /etc/php5/apache2/php.ini
    

    change `max_execution_time = 30' as max_execution_time = 300

    3.5 restart after cfg

    $ sudo /etc/init.d/apache2 restart
    

    4 config upload directory

    $ cd /var/www
    $ sudo mkdir uploads
    $ sudo chmod -R a+w uploads
    

    5 write sup.php (store in /var/www/html)

    contents as below:

    <?php
    $uploaddir = '/var/www/uploads/';
    $uploadfile = $uploaddir . basename($_FILES['xx_upload']['name']);
    
    if (is_uploaded_file($_FILES['xx_upload']['tmp_name'])) {
        echo "File " . $_FILES['xx_upload']['name'] . " uploaed ok.
    ";
    
        if (file_exists($uploadfile)) {
            echo "file exist.
    ";
        }
        else {
            if (move_uploaded_file($_FILES['xx_upload']['tmp_name'], $uploadfile)) {
                echo "File process ok.
    ";      
            }
        }
    }
    else {
        echo "Possible file upload attack!
    ";
        print_r($_FILES);
    }
    
    ?>
    

    6 upload by using curl in shell

    curl -F xx_upload=@/home/user_name/a.mp4 http://server_ip/sup.php
    

    Attention: `xx_upload' is used in `sup.php', as the first index of `_FILES'

  • 相关阅读:
    CodeForces 687B Remainders Game
    CodeForces 689D Friends and Subsequences
    CSU 1810 Reverse
    生成树收录
    吃奶酪
    带逆向思维的并查集
    中位数定理
    种类并查集(关押犯人)
    带权并查集
    分层图
  • 原文地址:https://www.cnblogs.com/aqing1987/p/5012825.html
Copyright © 2011-2022 走看看