4

A client's site uploads files, but if these files are large, the time-out error 503 Service Unavailable is returned.

The hopedagem limits the time out in 300 seconds, is there any way via js or related, to upload without time out? Uploads are videos.

The hosting server does not allow time out editing.

Bilal Ahmed
  • 4,005
  • 3
  • 22
  • 42
sNniffer
  • 210
  • 2
  • 19

3 Answers3

5

Go to php.ini file and change value with respect to your requirements.

upload_max_filesize

By default this value is 2M. We need to increase it to the maximum size of single file that we want to upload.

max_input_time

This sets the maximum time in seconds a script is allowed to parse input data, like POST and GET. Timing begins at the moment PHP is invoked at the server and ends when execution begins. This would include populating $_FILES superglobal.

memory_limit

This sets the amount of memory a PHP script is allowed to use during its execution. Set this to a value greater than ‘post_max_size’ so that PHP script can load and process the uploaded file.

post_max_size

It defines the maximum size of POST data that PHP will accept. This value should be greater than ‘upload_max_filesize’.

max_execution_time

The time a script is allowed to run after its input has been parsed. This would include any processing of the file itself.

If you are getting memory related error then turn off the output buffering, the PHP configuration directive to be considered is “output_buffering

output_buffering = Off

Also i add reference of above configuration and you can find more details here

Community
  • 1
  • 1
Bilal Ahmed
  • 4,005
  • 3
  • 22
  • 42
  • Hi, thanks my friend. The server does not allow the editing of `max_execution_time` is limited to 300 seconds, I have already edited the other items but, unsuccessfully – sNniffer Aug 29 '18 at 04:58
  • if you can't change on server side then you can add this line on top of the php script or file `ini_set('max_execution_time', 300); //300 seconds = 5 minutes` – Bilal Ahmed Aug 29 '18 at 05:25
2

You need to change some setting in your php.ini :

upload_max_filesize = 500M 
;or whatever size you want

max_execution_time = 1000
; also, higher if you must - sets the maximum time in seconds
Akbar Soft
  • 1,028
  • 10
  • 19
0

Resolved with: https://www.plupload.com/

    <div id="uploader">
        <p>Your browser doesnt have Flash, Silverlight or HTML5 support.</p>
    </div>


    <link href="https://rawgithub.com/moxiecode/plupload/master/js/jquery.plupload.queue/css/jquery.plupload.queue.css" type="text/css" rel="stylesheet" media="screen">
    <script type="text/javascript" src="assets/uploads/jquery-ui.js"></script>
    <script type="text/javascript" src="assets/uploads/plupload.full.min.js"></script>
    <script type="text/javascript" src="assets/uploads/jquery.plupload.queue/jquery.plupload.queue.min.js"></script>
    <script type="text/javascript" src="assets/uploads/jquery.ui.plupload/jquery.ui.plupload.min.js"></script>
    <link type="text/css" rel="stylesheet" href="assets/uploads/jquery.ui.plupload/css/jquery.ui.plupload.css" media="screen" />

    <script type="text/javascript" src="assets/uploads/i18n/pt_BR.js"></script>


    <script type="text/javascript">
    $(function() {
        $("#uploader").plupload({
            // General settings
            runtimes : 'html5,flash,silverlight,html4',
            url : "controller/xml_upload.php",

            // Maximum file size
            max_file_size : '2048mb',

            chunk_size: '1mb',

            // Specify what files to browse for
            filters : [
                {title : "XML", extensions : "xml"}
            ],

            // Rename files by clicking on their titles
            rename: true,

            // Sort files
            sortable: true,

            // Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
            dragdrop: false,

            // Views to activate
            views: {
                list: false,
                thumbs: false, // Show thumbs
                active: 'thumbs'
            },

            // Flash settings
            flash_swf_url : '/videos_add1_up/Moxie.swf',

            // Silverlight settings
            silverlight_xap_url : '/videos_add1_up/Moxie.xap',

            multipart_params : {
                "xml_usuario" : "xml_user"
            }
        });
    });
    </script>

PHP

    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    @set_time_limit(5 * 60);
    $targetDir = '../../assets/arquivos/xml/';
    $cleanupTargetDir = true; 
    $maxFileAge = 5 * 3600; 

    if (!file_exists($targetDir)) {
        @mkdir($targetDir);
    }

    if (isset($_REQUEST["name"])) {
        $fileName = $_REQUEST["name"];
    } elseif (!empty($_FILES)) {
        $fileName = $_FILES["file"]["name"];
    } else {
        $fileName = uniqid("file_");
    }




    include '../../_config.php';

    $filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName;

    // Chunking might be enabled
    $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
    $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;


    if ($cleanupTargetDir) {
        if (!is_dir($targetDir) || !$dir = opendir($targetDir)) {
            die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
        }

        while (($file = readdir($dir)) !== false) {
            $tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file;

            // If temp file is current file proceed to the next
            if ($tmpfilePath == "{$filePath}.part") {
                continue;
            }

            // Remove temp file if it is older than the max age and is not the current file
            if (preg_match('/\.part$/', $file) && (filemtime($tmpfilePath) < time() - $maxFileAge)) {
                @unlink($tmpfilePath);
            }
        }
        closedir($dir);
    }   


    if (!$out = @fopen("{$filePath}.part", $chunks ? "ab" : "wb")) {
        die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
    }

    if (!empty($_FILES)) {
        if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) {
            die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
        }

        // Read binary input stream and append it to temp file
        if (!$in = @fopen($_FILES["file"]["tmp_name"], "rb")) {
            die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
        }
    } else {    
        if (!$in = @fopen("php://input", "rb")) {
            die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
        }
    }

    while ($buff = fread($in, 4096)) {
        fwrite($out, $buff);
    }

    @fclose($out);
    @fclose($in);

    // Check if file has been uploaded
    if (!$chunks || $chunk == $chunks - 1) {
        // Strip the temp .part suffix off 
        rename("{$filePath}.part", $filePath);
    }
sNniffer
  • 210
  • 2
  • 19