+) anytime during this script is operation if you feel you have made a mistake\r\n"; //if the filepath, filename, username, or password are empty, prompt for values. //Take input from user if ($user == ''){ echo "Username: "; $user = fopen ("php://stdin","r"); $line = fgets($user); if(trim($line) == ''){ die("Please give your username\r\n"); } $user = trim($line); echo "Your username is: ".$user."\n"; } if ($pass == ''){ echo "Password: "; $pass = fopen ("php://stdin","r"); $line = fgets($pass); if(trim($line) == ''){ die("Please give your password\r\n"); } $pass = trim($line); echo "Your password is: ".$pass."\n"; } if ($filepath == ''){ echo "Please type the absolute path to the file with the trailing slash: "; $filepath = fopen ("php://stdin","r"); $line = fgets($filepath); if(trim($line) == ''){ die("Please give the absolute path to the file with the trailing slash\r\n"); } $filepath = trim($line); echo "The path to your file is: ".$filepath."\n"; } if ($filename == ''){ echo "Please type the full filename including the extension: "; $filename = fopen ("php://stdin","r"); $line = fgets($filename); if(trim($line) == ''){ die("Please give the full filename of what you wish to upload with the extension\r\n"); } $filename = trim($line); echo "Your filename is: ".$filename."\n"; } echo "This is your file you're uploading".$filepath.$filename."\nDo you accept it? (yes/no): "; $line = fopen ("php://stdin","r"); $line = fgets($line); if(trim($line) != 'yes'){ if(trim($line) != 'no'){ die("It appears your choice was invalid. Please try again"); } die("It appears you didn't want to upload that particular file. Please try again"); } //end input from user //read the entire contents of the file into a variable (I have a feeling this is going to eat ram for large files, but there's a 200MB limit for most users) $old = fopen($filepath.$filename, "r"); while(!feof($old)) { $thefile .= fgets($old); } //build the header to send to the server $header = "PUT /create?".$filename ." HTTP/1.0\r\n"; //create script on server using HTTP/1.0 $header .= "X-Foxscreen-User: ". $user ."\r\n"; //username header $header .= "X-Foxscreen-Password: ". $pass ."\r\n"; //password header $header .= "Host: foxcav.es\r\n"; //host $header .= "Content-Length: " . strlen($thefile)."\r\n\r\n"; //length in bytes of the file echo "\r\n\r\nThis is what the header should look like:\r\n".$header; //show the constructed header for debugging if something goes wrong //open connection to the server here $fp = fsockopen("ssl://foxcav.es", 443, $errno, $errstr, 60); //hardcoded to foxcaves because that's what this script is for if(!$fp) { return "unable to connect"; //general error - should only happen if server is offline or something } else { fputs ($fp, $header.$thefile); //push the connection and the header to the server, then append the raw data of the file after the header while (!feof($fp)) // while the connection to the server is open... { $result .= fread ($fp, 1024); //read server reply into result } fclose($fp); //close connection to server } echo $result."\r\n"; //print reply from the server $link = explode("\n", $result); //seperate the lines of the server reply echo "\r\nYour final uploaded link is:\r\nhttp://foxcav.es/".$link[12]."\r\n\r\n"; //newline then show the base (http://foxcav.es/) append the 12th line of the server reply (which will always be the link unless the upload fails in some way, but it should be error proof enough) //and append two more new lines for nicer formatting of output /* * SUCESSFUL UPLOAD EXAMPLE: * * HTTP/1.1 200 OK * Server: nginx/1.3.7 * Date: Fri, 12 Oct 2012 00:23:33 GMT * Content-Type: text/plain * Content-Length: 15 * Connection: close * X-XSS-Protection: 0 * X-Frame-Options: sameorigin * X-Powered-By: Lua 5.1, LuaJIT 2.0.0 * Strict-Transport-Security: max-age=315360000; includeSubdomains * * view/5RliUtHoE5 * * Your final uploaded link is: * http://foxcav.es/view/5RliUtHoE5 * */ ?> Creative Commons License
FoxCaves PHP Uploader by David Todd is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.