Monday, January 30, 2012

PHP upload files

<?php
        $target = "/usr/upload/mdp/";

        # Query strings
        #       op      - operator
        #       s       - site
        #       i       - instance name
        #       d       - date
        #
        # Example:  curl  -F file=@torrent/string.torrent -H "Expect:"  'http://203.197.173.13/mdp/rc/rc.php?op=vftr&s=psk&i=wap1&d=201102'

        $p = $target . $_REQUEST['op']."/".$_REQUEST['s']."/".$_REQUEST['i']."/".$_REQUEST['d']."/" ;

        if (! file_exists($p))
        {
                # create the dir
                mkdir ($p, 0755, true) or exit ("");
        }

        $target = $p . basename( $_FILES['file']['name']) ;
        if(move_uploaded_file($_FILES['file']['tmp_name'], $target))
        {
                #echo "The file ". basename( $_FILES['file']['name']). " has been uploaded";
        }
        else {
                #echo "Sorry, there was a problem uploading your file $target";
        }
 ?>