gdhami

Resumable PHP Upload

Feb 29th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.51 KB | None | 0 0
  1. <?php
  2.     set_time_limit(0);
  3.     header('Content-Type: text/html; charset=utf-8');
  4.     header('Accept-Ranges: bytes');
  5.  
  6.     $file_name = base64_decode( strtr($_POST["file_name"], '-_,', '+/=') );
  7.     if ( $file_name !== "" )
  8.     {
  9.         $file_handle      = fopen("/full/path/$file_name", "a+");
  10.         $php_input_handle = fopen("php://input", "r");
  11.  
  12.         while ( $data_chunk = fread($php_input_handle, 4096) )
  13.         {
  14.             fwrite($file_handle, $data_chunk, strlen($data_chunk));
  15.         }
  16.  
  17.         fclose($file_handle);
  18.         fclose($php_input_handle);
  19.     }
  20. ?>
Advertisement
Add Comment
Please, Sign In to add comment