ubuntu curl upload file to apache2 server

 

.title { text-align: center }
.todo { font-family: monospace; color: rgba(255, 0, 0, 1) }
.done { color: rgba(0, 128, 0, 1) }
.tag { background-color: rgba(238, 238, 238, 1); font-family: monospace; padding: 2px; font-size: 80%; font-weight: normal }
.timestamp { color: rgba(190, 190, 190, 1) }
.timestamp-kwd { color: rgba(95, 158, 160, 1) }
.right { margin-left: auto; margin-right: 0; text-align: right }
.left { margin-left: 0; margin-right: auto; text-align: left }
.center { margin-left: auto; margin-right: auto; text-align: center }
.underline { text-decoration: underline }
#postamble p, #preamble p { font-size: 90%; margin: 0.2em }
p.verse { margin-left: 3% }
pre { border: 1px solid rgba(204, 204, 204, 1); box-shadow: 3px 3px 3px rgba(238, 238, 238, 1); padding: 8pt; font-family: monospace; overflow: auto; margin: 1.2em }
pre.src { position: relative; overflow: visible; padding-top: 1.2em }
pre.src:before { display: none; position: absolute; background-color: rgba(255, 255, 255, 1); top: -10px; right: 10px; padding: 3px; border: 1px solid rgba(0, 0, 0, 1) }
pre.src:hover:before { display: inline }
pre.src-sh:before { content: “sh” }
pre.src-bash:before { content: “sh” }
pre.src-emacs-lisp:before { content: “Emacs Lisp” }
pre.src-R:before { content: “R” }
pre.src-perl:before { content: “Perl” }
pre.src-java:before { content: “Java” }
pre.src-sql:before { content: “SQL” }
table { border-collapse: collapse }
caption.t-above { caption-side: top }
caption.t-bottom { caption-side: bottom }
td, th { vertical-align: top }
th.right { text-align: center }
th.left { text-align: center }
th.center { text-align: center }
td.right { text-align: right }
td.left { text-align: left }
td.center { text-align: center }
dt { font-weight: bold }
.footpara:nth-child(0n+2) { display: inline }
.footpara { display: block }
.footdef { margin-bottom: 1em }
.figure { padding: 1em }
.figure p { text-align: center }
.inlinetask { padding: 10px; border: 2px solid rgba(128, 128, 128, 1); margin: 10px; background: rgba(255, 255, 204, 1) }
#org-div-home-and-up { text-align: right; font-size: 70%; white-space: nowrap }
textarea { overflow-x: auto }
.linenr { font-size: smaller }
.code-highlighted { background-color: rgba(255, 255, 0, 1) }
.org-info-js_info-navigation { border-style: none }
#org-info-js_console-label { font-size: 10px; font-weight: bold; white-space: nowrap }
.org-info-js_search-highlight { background-color: rgba(255, 255, 0, 1); color: rgba(0, 0, 0, 1); font-weight: bold }

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.\n";

    if (file_exists($uploadfile)) {
        echo "file exist.\n";
    }
    else {
        if (move_uploaded_file($_FILES['xx_upload']['tmp_name'], $uploadfile)) {
            echo "File process ok.\n";      
        }
    }
}
else {
    echo "Possible file upload attack!\n";
    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’

Related Posts

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注