• Hi guys
    My website has different layout to upload their file, and i’m using media_handle_upload() to handle that. The large file upload via media page is still good. I dont know what happend, can someone help me solve this. Here is my code to handle the uploaded file.

    
    if (empty($_FILES) || $_FILES['file']['error']) {
                verbose(0, "Failed to move uploaded file.");
            }
            $filePath = wp_upload_dir()['path'];
            $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : $_FILES["file"]["name"];
            $filePath = $filePath . '/' . $fileName;
            $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
            $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
            $out = @fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
            if ($out) {
                $in = @fopen($_FILES['file']['tmp_name'], "rb");
                if ($in) {
                    while ($buff = fread($in, 4096)) {
                        fwrite($out, $buff);
                    }
                } else {
                    verbose(0, "Failed to open input stream");
                }
                @fclose($in);
                @fclose($out);
            } else {
                verbose(0, "Failed to open output stream");
            }
    
            if (!$chunks || $chunk == $chunks - 1) {
                rename("{$filePath}.part", $filePath);
            }
    
            $_FILES['file']['name'] = $fileName;
            $_FILES['file']['size'] = filesize($filePath);
            $_FILES['file']['type'] = get_mime_content_type($filePath);
    
            $post_id = 0;
    
            $id = media_handle_upload('file', $post_id);
    
  • The topic ‘Error when uploading large file using media_handle_upload()’ is closed to new replies.