Topic: Problems implementing Plupload

First of all, congrats for the great work you've been doing with Plupload; it's awesome!

Second, please bear with me as I'm brazilian and english is not my native language. =]

Now comes the bad part. I simply can't make Plupload work and while serching all over this forum I discovered that it's my fault, (lack of knowledge). I'm still in the process of learning PHP and JS is the next thing on my list to learn.

What happens? Plupload shows nicely on my website and behaves as it should, but the files won't show up on my ftp. I won't post any code here for all I've seen in this forum I know it's missing some (or a lot) of things.

I think the 'server-side' part is my problem. I think that somewhere I have to start a connection with my host or do something like this and change the upload.php to feet my needs, but I don't know how to accomplish neither tasks. =(

My website is publishyours.com.br and I really hope someone can help a newbie like me. Please drop me a message if you can help or post here your thoughts.

Thanks a lot!

Re: Problems implementing Plupload

Check out the examples that come with plupload.  They have both the javascript code needed in the web-browser and sample php code for the server.  It looks like your server is using PHP for the server side processing so it should be "relatively" simple to put together something using the examples from plupload.

Re: Problems implementing Plupload

Hey Mike, thanks for your reply!

Well, I checked most (if not all) of the examples that comes with the package. Actually, I was able to put everything together and make as least show up online because I build my files side-by-side with the working examples.

My problem (I believe) lies in the server-side of the process. I read someone say in this forum that those files shipped with Plupload are only examples and there are some changes that I have to do to make it work properly.

Maybe I need more time with the code. I visited two topics with people with the same problem as mine (files will upload but don't show up on server) and they just post they solved their problem but it's not clear to me why they did or what they've changed on their codes (I wish they shared the working code too) to make it work.

I'm not at home now to do so, but maybe I should post what I have and see if you can spot what's wrong or what's missing.

Again, thanks for your attention and time Mike!

Re: Problems implementing Plupload

Find $targetDir variable in upload.php (if you are using it) and change the path to the directory location that you are sure exists.

If you want to see your issue fixed, do not report it here, do it on - GitHub.

5 (edited by 7th 2011-04-06 19:51:36)

Re: Problems implementing Plupload

It's done Davit (and I've tried different things too). Trust me when I say I did some research here on the forum, read some discussions and topics (from top to bottom), tried different examples and everything is working fine but the files that won't show up on the server.

Maybe you should wait until later today when I'll be able to share what I have. But I would love to understand what people mean when they say that we're supposed to adjust/tweak the given example codes to suit our needs.

And thanks for your help! Again, the work you're doing here is amazing, and the support is equaly impressive (it's fast to say the least) smile

ps.: I was really afraid I would have to wait days to get any answer on this topic =]

Re: Problems implementing Plupload

Hi 7th

Try setting your target to:

$targetDir = $_SERVER["DOCUMENT_ROOT"] . DIRECTORY_SEPARATOR . "plupload";

where "plupload is a directory off the root of your domain.

I managed to get mine working on a live server but not locally, although I think this is because I'm using IIS7.

Re: Problems implementing Plupload

Thank you Andy, but it didn't worked sad

Well, I think it's time to share some code. First I would like to enphasize that I'm not (anywhere in my code) starting a connection to the host or inserting the username or password that I have to have when I need to upload something manually to my ftp. I don't know if something like this is necessary and if it is, I have no idea about how I'm supposed to do that.

Also, I'm quire sure that the code is checking for the folders because if I use inside $targetDir something that doesn't exists, it will return an error right after the upload is finished.

So, first my header.php where I'm loading the plupload script:

<!DOCTYPE HTML>
<html lang="<?php echo $lang['htmlLang']; ?>" >
    <head>
        <meta charset="UTF-8">
        <meta name="description" content="<?php echo $lang['slogan']; ?>" >
        <title><?php echo $lang['publish']; ?></title>
            <link rel="shortcut icon" href="../favicon.ico">
            <link rel="stylesheet" type="text/css" href="assets/css/main.css">
            <link rel="stylesheet" type="text/css" href="assets/scripts/sb/shadowbox.css">
            <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
            <?php if (pageName() == 'contact.php') { echo ''?>
                <script type="text/javascript" src="contact-form/js/jquery.form.js"></script>
                <script type="text/javascript" src="contact-form/js/jquery.iphorm.js"></script>
                <script type="text/javascript" src="contact-form/js/scripts.js"></script>
            <?php } ?>
            <?php if (pageName() == 'ftp.php') { echo ''?>
                <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" />
                <link rel="stylesheet" href="assets/css/jquery.ui.plupload.css" type="text/css" />
                <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
                <script type="text/javascript" src="assets/scripts/gears_init.js"></script>
                <script type="text/javascript" src="http://bp.yahooapis.com/2.4.21/browserplus-min.js"></script>
                <script type="text/javascript" src="assets/scripts/plupload.full.min.js"></script>
                <script type="text/javascript" src="assets/scripts/jquery.ui.plupload.min.js"></script>
                <script type="text/javascript">
                    // Convert divs to queue widgets when the DOM is ready
                    $( function() {
                        $("#uploader").plupload({
                            // General settings
                            runtimes : 'html5,flash,browserplus,silverlight,gears,html4',
                            url : 'uploader/upload.php',
                            max_file_size : '200mb',
                            max_file_count: 20, // user can add no more then 20 files at a time
                            chunk_size : '1mb',
                            unique_names : true,
                            multiple_queues : true,
                            // Resize images on clientside if we can
                            //resize : {width : 320, height : 240, quality : 90},
                            // Rename files by clicking on their titles
                            rename: true,
                            // Sort files
                            sortable: true,
                            // Specify what files to browse for
                            filters : [
                            {title : "webFiles", extensions : "jpg,png,gif"},
                            {title : "prepressFiles", extensions : "ai,pdf,tif,eps,ps"},
                            {title : "officeFiles", extensions : "txt,doc,docx,xls,xlsx"},
                            {title : "zipFiles", extensions : "zip"}
                            ],
                            // Flash settings
                            flash_swf_url : 'assets/scripts/plupload.flash.swf',
                            // Silverlight settings
                            silverlight_xap_url : 'assets/scripts/plupload.silverlight.xap'
                        });
                        // Client side form validation
                        $('form').submit( function(e) {
                            var uploader = $('#uploader').plupload('getUploader');
                            // Validate number of uploaded files
                            if (uploader.total.uploaded == 0) {
                                // Files in queue upload them first
                                if (uploader.files.length > 0) {
                                    // When all files are uploaded submit form
                                    uploader.bind('UploadProgress', function() {
                                        if (uploader.total.uploaded == uploader.files.length)
                                            $('form').submit();
                                    });
                                    uploader.start();
                                } else
                                    alert('You must at least upload one file.');
                                e.preventDefault();
                            }
                        });
                    });
                </script>
            <?php } ?>
            <!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
    </head>

And here is my upload.php file with some of my attempts:

<?php
/**
 * upload.php
 *
 * Copyright 2009, Moxiecode Systems AB
 * Released under GPL License.
 *
 * License: http://www.plupload.com/license
 * Contributing: http://www.plupload.com/contributing
 */

    // HTTP headers for no cache etc
    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");

    // Settings
    //$targetDir = ini_get("clients_dir") . DIRECTORY_SEPARATOR . "plupload";
    //$targetDir = ini_get("../clients_dir");
    //$targetDir = $_SERVER["DOCUMENT_ROOT"].DIRECTORY_SEPARATOR."Web";
    $targetDir = $_SERVER["DOCUMENT_ROOT"].DIRECTORY_SEPARATOR."Web/clients_dir";
    $cleanupTargetDir = false; // Remove old files
    $maxFileAge = 60 * 60; // Temp file age in seconds

    // 5 minutes execution time
    @set_time_limit(5 * 60);

    // Uncomment this one to fake upload time
    // usleep(5000);

    // Get parameters
    $chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0;
    $chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0;
    $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';

    // Clean the fileName for security reasons
    $fileName = preg_replace('/[^\w\._]+/', '', $fileName);

    // Make sure the fileName is unique but only if chunking is disabled
    if ($chunks < 2 && file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName)) {
        $ext = strrpos($fileName, '.');
        $fileName_a = substr($fileName, 0, $ext);
        $fileName_b = substr($fileName, $ext);

        $count = 1;
        while (file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName_a . '_' . $count . $fileName_b))
            $count++;

        $fileName = $fileName_a . '_' . $count . $fileName_b;
    }

    // Create target dir
    if (!file_exists($targetDir))
        @mkdir($targetDir);

    // Remove old temp files
    if (is_dir($targetDir) && ($dir = opendir($targetDir))) {
        while (($file = readdir($dir)) !== false) {
            $filePath = $targetDir . DIRECTORY_SEPARATOR . $file;

            // Remove temp files if they are older than the max age
            if (preg_match('/\\.tmp$/', $file) && (filemtime($filePath) < time() - $maxFileAge))
                @unlink($filePath);
        }

        closedir($dir);
    } else
        die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');

    // Look for the content type header
    if (isset($_SERVER["HTTP_CONTENT_TYPE"]))
        $contentType = $_SERVER["HTTP_CONTENT_TYPE"];

    if (isset($_SERVER["CONTENT_TYPE"]))
        $contentType = $_SERVER["CONTENT_TYPE"];

    // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5
    if (strpos($contentType, "multipart") !== false) {
        if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
            // Open temp file
            $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
            if ($out) {
                // Read binary input stream and append it to temp file
                $in = fopen($_FILES['file']['tmp_name'], "rb");
                if ($in) {
                    while ($buff = fread($in, 4096))
                        fwrite($out, $buff);
                } else
                    die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
                fclose($in);
                fclose($out);
                @unlink($_FILES['file']['tmp_name']);
            } else
                die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
        } else
            die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
    } else {
        // Open temp file
        $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
        if ($out) {
            // Read binary input stream and append it to temp file
            $in = fopen("php://input", "rb");

            if ($in) {
                while ($buff = fread($in, 4096))
                    fwrite($out, $buff);
            } else
                die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
            fclose($in);
            fclose($out);
        } else
            die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
    }
    // Return JSON-RPC response
    die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');
?>

Re: Problems implementing Plupload

I don't know if this is useful but my folder structure on the server goes like this:

In the root, 3 folders:
+Dados ("Data" in Portuguese)
+Logs
+Web

Inside Web I have my website and everything related to it (it's quite a mess for now):

Folders:
+aspnet_client (I don't know what this is, but it's always there)
+assets (within it: css/imgs and scripts, where I have all plupload scripts, including plupload.full.min.js and jquery.ui.plupload.min.js )
+clients_dir (where I'm willing to keep the uploaded files
+contact-form
+content
+includes
+uploader (where I have dump.php, s3.php and upload.php)

and in the Web root folder, I have my main .php files like ftp.php (the main page of Plupload on my website).

And again, my website is www.publishyours.com.br

Thanks in advance for all the time spent and help!

Re: Problems implementing Plupload

Ah, and I just checked the process with firefox and firebug and the uploader is returning the error "Failed to open temp directory".

The error comes from this part of the code:

if (is_dir($targetDir) && ($dir = opendir($targetDir))) {
        while (($file = readdir($dir)) !== false) {
            $filePath = $targetDir . DIRECTORY_SEPARATOR . $file;

            // Remove temp files if they are older than the max age
            if (preg_match('/\\.tmp$/', $file) && (filemtime($filePath) < time() - $maxFileAge))
                @unlink($filePath);
        }

        closedir($dir);
    } else
        die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');

I just checked the CHMOD properties of the folder and it's set to 777. But I don't have a temp directory set. =/

Re: Problems implementing Plupload

I cant get pupload to work either...please help!

Re: Problems implementing Plupload

@7th - have you printed out what your upload.php is actually setting the targetDir variable to?  It looks like it is having problems with permissions on that directory (either creating it, or using it?).

12

Re: Problems implementing Plupload

Hi Mike!

I did some tests as you suggested and I hope you find the results helpful (please remeber that I'm not a php savvy hehe).

So, what I first did was try this:

$targetDir = $_SERVER["DOCUMENT_ROOT"].DIRECTORY_SEPARATOR."publishyou1/Web";
echo "<br/>Echo TargetDir: ";
    echo $targetDir;
    
echo "<br/>Print_R TargetDir: ";
    print_r($targetDir);
    
echo "<br/>MakeDir: ";
    @mkdir($targetDir); (line 45)
    
echo "<br/>OpenDir: ";
    opendir($targetDir); (line 48)
    
echo "<br/>Echo OpenDir: ";
    echo opendir($targetDir);
    
echo "<br/>Echo Substr PageName: ";
    echo substr($_SERVER['SCRIPT_NAME'],strrpos($_SERVER['SCRIPT_NAME'],'/')+1);
    
echo "<br/>Print_R Substr PageName: ";
    print_r(substr($_SERVER['SCRIPT_NAME'],strrpos($_SERVER['SCRIPT_NAME'],'/')+1));
    
echo "<br/>Echo PageURL: ";
    echo pageURL();
echo "<br/>Print PageURL: ";
    print_r(pageURL());

And the result printed: Errors!

PHP Warning:  opendir(e:\home\publishyou1\Web\publishyou1/Web) [<a href='function.opendir'>function.opendir</a>]: failed to open dir: No error in E:\home\publishyou1\Web\uploader\upload.php on line 45
PHP Warning:  opendir(e:\home\publishyou1\Web\publishyou1/Web) [<a href='function.opendir'>function.opendir</a>]: failed to open dir: No error in E:\home\publishyou1\Web\uploader\upload.php on line 48
PHP Warning:  fopen(e:\home\publishyou1\Web\publishyou1/Web\) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in E:\home\publishyou1\Web\uploader\upload.php on line 138

Down on line 138 we have this (just so you know):

$out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");

When I began with the tests, everything would print (echo out) properly just for quoting out the line that asks to open the directory. Now it is always returning errors (for security reasons I guess, as I was doing a lot of tests).

My question, again: do I need to start a php session or connection before trying this? I think I just need this to work with databases but...

Re: Problems implementing Plupload

I don't use PHP myself, I use Ruby on Rails.  Perhaps someone else might help you debug your PHP.  Barring that I'd suggest doing some reading on PHP (e.g. http://www.php.net/docs.php).

14

Re: Problems implementing Plupload

Ok Mike. Thanks for your help. I'll keep waiting and see if someone else can help me. smile

ps.: For me, it's still too hard to learn with the documentation. I still need some base to start using the docs as a reference. But thaks for the tip. I'll keep that in mind!

Re: Problems implementing Plupload

Ok, from what you've described I assume that uploader/ is a directory where your upload.php resides, right? So try the following:

- Create folder uploads/ in uploader/ (uploader/uploads/)

- Set proper permissions on uploader/uploads/ directory (777)

- Set: $targetDir = "uploads"; in your upload.php

- Try to upload again.

If you want to see your issue fixed, do not report it here, do it on - GitHub.

16

Re: Problems implementing Plupload

Hi Davit! You got my folder structure right and I did as you asked.

Now when the upload finishes it returns (on Plupload, on screen):

IO error. 
Error #2032

Trying to go directly www.publishyours.com.br/uploader/upload.php it's returning the following error:

PHP Warning:  fopen(uploads\_1) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in E:\home\publishyou1\Web\uploader\upload.php on line 121

where line 121 is this:

$out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");

Firebug also report the error as a 500 Internal Server Error at my domain which I think is related to permissions.

The strange thing is that my folder's permissions are already set to 777 (at least is what I see on my ftp app).

On my PHP I'm not setting any connection to my ftp. I'm not using a username and password anywhere. If it's really not necessary, do you think it's a good idea to call my host and ask for help? If it is so, what would I ask them?

And I can't thank you enough for all the support and patience!

17

Re: Problems implementing Plupload

Davit! It's working! haha

I just called my host and was informed that I should double check the permission settings to my folder online instead of my ftp client. My ftp client was saying the folder was set to 777 but online it was set to "read only".

I made the change and now it's working like a charm!

So, @Loy yer and all the others with the same problem as mine (everything seems to be working but the files won't show online), double check the CHMOD config (permissions)!

Davit and all others involved in this project, you've done (and are doing) an awesome work! It took me days to choose an uploading tool for my website and I'm pretty sure I choose one of the best ones (if not the best one).

I'm very happy with it, really!

The only problem now (haha) is that all files uploaded get a strange name like: "p15sqrc9pa1rodula1ntsnn1at85.jpg". But this is just a small problem and I'm almost sure where to tweek to make it right.

Again, thank you all for the help and keep up the good work!

18

Re: Problems implementing Plupload

And here's my working code:

Inside my header tag (just what's related to Plupload:

//pageName() is a simple custom function to check current page name.
            <?php if (pageName() == 'ftp.php') { echo ''?>
                <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" />
                <link rel="stylesheet" href="assets/css/jquery.ui.plupload.css" type="text/css" />
                <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
                <script type="text/javascript" src="assets/scripts/gears_init.js"></script>
                <script type="text/javascript" src="http://bp.yahooapis.com/2.4.21/browserplus-min.js"></script>
                <script type="text/javascript" src="assets/scripts/plupload.full.min.js"></script>
                <script type="text/javascript" src="assets/scripts/jquery.ui.plupload.min.js"></script>
                <script type="text/javascript">
                    // Convert divs to queue widgets when the DOM is ready
                    $( function() {
                        $("#uploader").plupload({
                            // General settings
                            runtimes : 'html5,flash,browserplus,silverlight,gears,html4',
                            url : 'uploader/upload.php',
                            max_file_size : '200mb',
                            max_file_count: 20, // user can add no more then 20 files at a time
                            chunk_size : '1mb',
                            unique_names : true,
                            multiple_queues : true,
                            // Resize images on clientside if we can
                            //resize : {width : 320, height : 240, quality : 90},
                            // Rename files by clicking on their titles
                            rename: true,
                            // Sort files
                            sortable: true,
                            // Specify what files to browse for
                            filters : [
                            {title : "webFiles", extensions : "jpg,png,gif"},
                            {title : "prepressFiles", extensions : "ai,pdf,tif,eps,ps"},
                            {title : "officeFiles", extensions : "txt,doc,docx,xls,xlsx"},
                            {title : "zipFiles", extensions : "zip"}
                            ],
                            // Flash settings
                            flash_swf_url : 'assets/scripts/plupload.flash.swf',
                            // Silverlight settings
                            silverlight_xap_url : 'assets/scripts/plupload.silverlight.xap'
                        });
                        // Client side form validation
                        $('form').submit( function(e) {
                            var uploader = $('#uploader').plupload('getUploader');
                            // Validate number of uploaded files
                            if (uploader.total.uploaded == 0) {
                                // Files in queue upload them first
                                if (uploader.files.length > 0) {
                                    // When all files are uploaded submit form
                                    uploader.bind('UploadProgress', function() {
                                        if (uploader.total.uploaded == uploader.files.length)
                                            $('form').submit();
                                    });
                                    uploader.start();
                                } else
                                    alert('You must at least upload one file.');
                                e.preventDefault();
                            }
                        });
                    });
                </script>
            <?php } ?>

and inside upload.php I have the following code:
note that I'm following Davit's suggestion of creating an "uploads" folder within the same folder where I have upload.php file. Refer to his last post in this topic.

<?php
/**
 * upload.php
 *
 * Copyright 2009, Moxiecode Systems AB
 * Released under GPL License.
 *
 * License: http://www.plupload.com/license
 * Contributing: http://www.plupload.com/contributing
 */

    // HTTP headers for no cache etc
    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");
    
    
    // Settings
    $targetDir = "uploads";
    $cleanupTargetDir = false; // Remove old files
    $maxFileAge = 60 * 60; // Temp file age in seconds

    // 5 minutes execution time
    @set_time_limit(5 * 60);

    // Uncomment this one to fake upload time
    // usleep(5000);

    // Get parameters
    $chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0;
    $chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0;
    $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';

    // Clean the fileName for security reasons
    $fileName = preg_replace('/[^\w\._]+/', '', $fileName);

    // Make sure the fileName is unique but only if chunking is disabled
    if ($chunks < 2 && file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName)) {
        $ext = strrpos($fileName, '.');
        $fileName_a = substr($fileName, 0, $ext);
        $fileName_b = substr($fileName, $ext);

        $count = 1;
        while (file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName_a . '_' . $count . $fileName_b))
            $count++;

        $fileName = $fileName_a . '_' . $count . $fileName_b;
    }

    // Create target dir
    if (!file_exists($targetDir))
        @mkdir($targetDir);

    // Remove old temp files
    if (is_dir($targetDir) && ($dir = opendir($targetDir))) {
        while (($file = readdir($dir)) !== false) {
            $filePath = $targetDir . DIRECTORY_SEPARATOR . $file;

            // Remove temp files if they are older than the max age
            if (preg_match('/\\.tmp$/', $file) && (filemtime($filePath) < time() - $maxFileAge))
                @unlink($filePath);
        }

        closedir($dir);
    } else
        //die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');

    // Look for the content type header
    if (isset($_SERVER["HTTP_CONTENT_TYPE"]))
        $contentType = $_SERVER["HTTP_CONTENT_TYPE"];

    if (isset($_SERVER["CONTENT_TYPE"]))
        $contentType = $_SERVER["CONTENT_TYPE"];

    // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5
    if (strpos($contentType, "multipart") !== false) {
        if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
            // Open temp file
            $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
            if ($out) {
                // Read binary input stream and append it to temp file
                $in = fopen($_FILES['file']['tmp_name'], "rb");
                if ($in) {
                    while ($buff = fread($in, 4096))
                        fwrite($out, $buff);
                } else
                    die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
                fclose($in);
                fclose($out);
                @unlink($_FILES['file']['tmp_name']);
            } else
                die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
        } else
            die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
    } else {
        // Open temp file
        $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
        if ($out) {
            // Read binary input stream and append it to temp file
            $in = fopen("php://input", "rb");

            if ($in) {
                while ($buff = fread($in, 4096))
                    fwrite($out, $buff);
            } else
                die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
            fclose($in);
            fclose($out);
        } else
            die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
    }
    // Return JSON-RPC response
    die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');
?>

Re: Problems implementing Plupload

@7th, you get these strange filename because you got unique_names : true set, which generates unique guids for file were possible. Remove it and files will be uploaded under their original name.

If you want to see your issue fixed, do not report it here, do it on - GitHub.

20

Re: Problems implementing Plupload

It's done Davit, since my last post actually smile
But instead of removing it, I simply set it to false. Who knows if I'll ever need this =P

Looking in the code related to this feature, it seems it checks the server for files with the same name. I don't know how to do it but, instead of generating a random name like that, it would be better to just append an number (random maybe) at the end of the file name... Actually I think I can do that (or try at least).

Well, it's just an idea to keep the same feature working but with better results for the user.

And thanks yet again! smile

Re: Problems implementing Plupload

Bundled upload.php does that - appends number to the name. But only when chunking is disabled. With chunking turned on, it's not possible.

If you want to see your issue fixed, do not report it here, do it on - GitHub.

22

Re: Problems implementing Plupload

Good to know... I'll try that later. Thanks Davit wink