plupload_element_value() has this code to find values based on $form_state['input'] keys:

  $files = array();
  foreach ($form_state['input'] as $key => $value) {
    if (preg_match('/' . $id . '_([0-9]+)_(.*)/', $key, $reg)) {
      $i = $reg[1];
      $key = $reg[2];
      $files[$i][$key] = $value;
    }
    $files[$i]['tmppath'] = variable_get('plupload_temporary_uri', 'temporary://') . $files[$i]['tmpname'];
  }

However, when the preg_match does not match, $i will be undefined (or the previous value), and $files[$i] will throw a notice for $i being undefined much like $files[$i]['tmpname'] being undefined. Not sure why is this last line out of the if(). $files starts off as an empty array and we only ever set any $files[$i][$key] when we know $key is like $id_(number)_(something), which does not sound like it is ever going to be tmpname?!?

Immediate workaround to check for !empty($i) attached but still not sure about how this is supposed to work.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eigentor’s picture

Can confirm this and in consequence cannot upload any files. Get a nice error message though:

    * Notice: Undefined variable: i in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined index: in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined variable: i in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined variable: i in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined index: tmpname in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined variable: i in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined variable: i in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined index: tmpname in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined variable: i in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined variable: i in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined index: tmpname in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined variable: i in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined variable: i in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined index: tmpname in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined variable: i in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined variable: i in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined index: tmpname in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined variable: i in plupload_element_value() (line 113 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Notice: Undefined index: name in plupload_element_validate() (line 141 of /var/www/auweia.org/htdocs/test/drupal-head-media/sites/all/modules/plupload/plupload.module).
    * Only files with the following extensions are allowed: jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp mp3 mov m4v mp4 mpeg avi ogg wmv ico.


eigentor’s picture

Can confirm Gabors patch makes the error message go away. Still no files get uploaded at my site, but this may be due to some misconfiguration. Since the installation profile media_dev does not work, I tried installing all the modules manually and get strange errors when trying to upload and insert files:

Fatal error: Unsupported operand types in /var/www/auweia.org/htdocs/test/drupal-head-media/modules/field/field.info.inc on line 355 
slashrsm’s picture

Priority: Normal » Major
Status: Needs review » Needs work

I can confirm, that error messages diappear with this patch, but upload still do not work.

I believe that there is a problem with uploaded files, since it looks to me, that they are not passed to plupload_element_value(). I checked the $form_state['input'] and found out that $form_state['input']['edit-upload_count'] always gets value 0. I believe this should be the number of uploaded files, so always >0?

benanderson’s picture

subscribe: I'm experience the same issue...

eigentor’s picture

Still same error message with latest dev of plupload. No files get uploaded.

Sebastian.Buesing’s picture

Hi, also having this issue. *subscribe*

Can confirm the part where "$form_state['input']['edit-upload_count'] always gets value 0" ;)

sea4’s picture

+1 having the same issues

Sebastian.Buesing’s picture

Hi,
I did some debugging. At nothing worked but when you look at this code...

function plupload_handle_uploads() {
...
if (empty($file_name) || !preg_match('/^[\w\._]+\.tmp$/', $file_name)) {

...and if you uncomment the...

!preg_match('/^[\w\._]+\.tmp$/', $file_name)

...part my files get uploaded but still don't reach the "plupload_element_value". No solution yet, but maybe this helps sb else ;).

Also I have installed this now on 3 different plattforms (using latest drupal dev) so I'm not sure this is a simple config error.

Greetings,
Sebastian

Sebastian.Buesing’s picture

Hi again :),

well I did some further debugging. First mistake I already mentioned is that some how $_REQUEST['name'] doesn't end on .tmp. Not sure if this is a configuration error. I couldn't find anything alike. For the part of the files not getting processed I wrote some workaround which you are free to test, before I or anyone else (feel free to do it) puts them in a patch. Well here they are:

in plupload_handle_uploads:

replace:

$file_name = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';

with:

$file_name = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
  // <WORKAROUND>
  // @TODO: check why this is necessary:
  $info = pathinfo($temp_directory . DIRECTORY_SEPARATOR . $file_name);
  // if no .tmp copy
  if(is_array($info) && $info['extension'] != '.tmp') {
    $in = fopen($temp_directory . DIRECTORY_SEPARATOR . $file_name, "rb");
    if ($in) {
      // Read binary input stream and append it to temp file
      $out = fopen($temp_directory . DIRECTORY_SEPARATOR . $info['filename'] . '.tmp', "rb");
      if ($in) {
        while ($buff = fread($in, 4096)) {
          fwrite($out, $buff);
        }
      }
    }
    $file_name = $info['filename'] . '.tmp';
    unlink($temp_directory . DIRECTORY_SEPARATOR . $info['filename'] . $info['extension']);
  }
  // </WORKAROUND>

and

if (isset($_SERVER["CONTENT_TYPE"])) {
    $content_type = $_SERVER["CONTENT_TYPE"];
  }

with

if (isset($_SERVER["CONTENT_TYPE"])) {
    $content_type = $_SERVER["CONTENT_TYPE"];
  }
  // @TODO: find better solution here
  // upload bug workaround: for some reason $form_state['input'] doesn't have any
  // data in it, when plupload_element_value is called
  if(!isset($_SESSION['_plupload_files']))
    $_SESSION['_plupload_files'] = array();
  $_FILES['file']['tmpname'] = $file_name;
  $_SESSION['_plupload_files'][] = $_FILES['file'];
  // END WORKAROUND

almost there...now replace in plupload_element_value

$files = array();

with

$files = array();
  // @TODO: find better solution
  // WORKAROUND (see plupload_handle_uploads and
  // http://drupal.org/node/953242
  if(isset($_SESSION['_plupload_files'])) {
    foreach($_SESSION['_plupload_files'] as $index => $file) {
      $files[$index]['name'] = $file['name'];
      $files[$index]['type'] = $file['type'];
      $files[$index]['status'] = 'done';
      $files[$index]['tmpname'] = $file['tmpname'];
      $files[$index]['tmppath'] = variable_get('plupload_temporary_uri', 'temporary://') . $file['tmpname'];
    }
    unset($_SESSION['_plupload_files']);
  } // END WORKAROUND - leaving old code in else part
  else
  {
    foreach ($form_state['input'] as $key => $value) {
      if (preg_match('/' . $id . '_([0-9]+)_(.*)/', $key, $reg)) {
        $i = $reg[1];
        $key = $reg[2];
        $files[$i][$key] = $value;
      }
      if(!empty($i))
        $files[$i]['tmppath'] = variable_get('plupload_temporary_uri', 'temporary://') . $files[$i]['tmpname'];
      }
  }

This should allow you to upload again, if you had the same problem as I did. However this is not a real solution to the problem but merely a workaround.

Greetings,
Sebastian

mathiasgmeiner’s picture

Hey thanks for this workaround!

I modified it a little bit to get it working, I repleaced every variable_get('plupload_temporary_uri', 'temporary://') with file_directory_temp(). I'm able to upload files, but sometimes it acts a little bit strange. So, not stable at all!

In "plupload_element_value" from:
$files[$index]['tmppath'] = variable_get('plupload_temporary_uri', 'temporary://') . $file['tmpname'];
to
$files[$index]['tmppath'] = file_directory_temp() .'/'. $file['tmpname'];

In "plupload_handle_uploads" from:
$temp_directory = variable_get('plupload_temporary_uri', 'temporary://');
to
$temp_directory = file_directory_temp();

rudders’s picture

+1 for the error - subscribing

ricodol’s picture

Dear all,

+1 for the error -subscribing

I try the workaround #9 and #10
but

Warning: fopen(/tmp/p15mrjsnbq8q41bcbg171mgrchc1.jpeg) [function.fopen]: failed to open stream: No such file or directory in plupload_handle_uploads() (line 280 of /www/--/sites/all/modules/plupload/plupload.module).
Warning: unlink(/tmp/p15mrjsnbq8q41bcbg171mgrchc1jpeg) [function.unlink]: No such file or directory in plupload_handle_uploads() (line 291 of /www/--/sites/all/modules/plupload/plupload.module).

it seems there is an error with $temp_directory ?
so If someone have some ideas I would be happy to test them..

Bruno

ricodol’s picture

the line is in the workaround

    $in = fopen($temp_directory . DIRECTORY_SEPARATOR . $file_name, "rb");

proposed in #9 in function
plupload_handle_uploads() {

so if someone could post a working pluload.module (or near working) I will be pleased
thks
Bruno

greggles’s picture

Assigned: Unassigned » effulgentsia

Let's see if assigning this to effulgentsia helps get attention ;)

Rj-dupe-1’s picture

subscribe

effulgentsia’s picture

Status: Needs work » Needs review
FileSize
763 bytes

I'm not sure if this is right, but posting a quick stab. Will look more into it later, but if anyone wants to post results, that would help.

ricodol’s picture

FileSize
20.92 KB

Thks for your post,

I apply the patch on 7.x-1.x-dev
now no more php error

BUT no upload
I selecte files, upload start, the plupload element disappear (i made screen shot) at the end of all upload files

I don t know if it s related to plupload or Media Gallery (7.x-1.0-beta3)

If you have ideas I m open to test,
thks again for your work,
Bruno

hasdf’s picture

Tested with Plupload 7.x-1.x-dev and Media Gallery 7.x-1.0-beta3,

I have the same results as ricodol posted. But in my Case, the plupload element is just replaced with the standard upload for media.

Thanks for your work. I will try testing it on a fresh drupal install...

Martin

carwin’s picture

subscribe

Tiktaalik’s picture

Subscribe.

mathiasgmeiner’s picture

This patch is the summary of all the workarounds and patches until #953242-16: Undefined $i wreaks havoc in plupload_element_value(). It works for me at two different Drupal-installations.

It has still bugs: e.g. upload in Google Chrome (9.0.597.84 beta) isn't working,...

sudotrin’s picture

#21 worked for me! Thank you!!

As an aside - I noticed earlier when I was trying to get this to work that there was an issue with getting the '.' between the name and extension in Chrome. I've been going through and trying to find the point when that happened to no avail. Also when using this in Opera, if there are spaces in the file name it errors - but still uploads the file.

Error message
The specified file /tmp/p15o8ho78e1cro17pcmpvirv1n0s1.jpg could not be copied, because no file by that name exists. Please check that you supplied the correct filename.
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 2: INSERT INTO {file_managed} (uid, filename, uri, filemime, filesize, status, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => [:db_insert_placeholder_2] => [:db_insert_placeholder_3] => application/octet-stream [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => 1297367183 ) in drupal_write_record() (line 6776 of /home/thestic3/public_html/sadoldcow.com/includes/common.inc).

Also this in the error console:

JavaScript - http://www.sadoldcow.com/admin/content/media

Uncaught exception: TypeError: Cannot convert 'this.contentWindow.Drupal.media' to object
Error thrown at line 101, column 2 in <anonymous function: Drupal.media.popups.mediaBrowser.mediaBrowserOnLoad>(e) in http://www.sadoldcow.com/sites/all/modules/media/javascript/media.popups.js?v=7.x:
    if (this.contentWindow.Drupal.media.browser.selectedMedia.length > 0)
called via Function.prototype.apply() from line 65, column 303 in <anonymous function: handle>(a):
    a.handleObj=k;
called via Function.prototype.apply() from line 58, column 835 in <anonymous function: o>():
    return typeof c!=="undefined"&&!c.event.triggered?c.event.handle.apply(o.elem,
DonZeptero’s picture

i modified the workaround a little, now it workes for me without warning and error.

plupload version: 7.x-1.0-beta1
media version: 7.x-1.x-dev
media gallery version: 7.x-1.0-beta3

DonZeptero

Tiktaalik’s picture

Hi,

Using DonZeptero's -22 patch, I get the following:

    * The specified file /tmp/p15obur5rjfmcf648m5n34ks93.JPG could not be copied, because no file by that name exists. Please check that you supplied the correct filename.
    * PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'uri': INSERT INTO {file_managed} (uid, filename, uri, filemime, filesize, status, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => [:db_insert_placeholder_2] => [:db_insert_placeholder_3] => application/octet-stream [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => 1297481572 ) in drupal_write_record() (line 6776 of /var/www/thegreenfamily.id.au/htdocs/drupal/includes/common.inc).

after I attempt to drag-drop a single JPG image.

joelving’s picture

Hi,
Using #22's patch, I get the same errors as #24. The files will reside in the temp-folder with the temporary filenames.
If, however, I comment out the unlinking of the files (~line 290), the first file in the series will be moved to the files folder and renamed properly. At this point I get the same error, which suggests that while plupload returns the correct objects for further processing, the module actually responsible for the move neglects to update the path from the temp-folder to the files folder, which in my case of course prevents Media Gallery from creating the nodes.

I hope someone can use this, as I have nowhere near the experience nor knowledge required to actually figure out what is going on behind the scenes. :)

Btw, should the in-stream not be closed as well when we're done reading from it? (~line 280).

camdarley’s picture

subscribe

ricodol’s picture

Using #22's patch, I get the same errors as #24 and # 25

So hope someone with knowledge (and time..) would take care of the situation.
because
I don't know an alternative to upload a lot of image or media in media gallery ?
I don't know if media gallery could create nodes from local images (import by ftp) ?

so any advance in plupload integration would be benefit.

BRuno

elgandoz’s picture

sub

elgandoz’s picture

FileSize
274.2 KB

I used the plupload module from drupalgardens.com, and it simply works. no errors displayed, no patches needed.
Why is not possible put this version as "Satble" or as "Working beta" at least, instead of 2 not-working modules?
test the attached module (by Acquia), no extra download needed.

Works as expected with

  • media 7.x-1.0-beta3
  • media_browser_plus 7.x-1.0-beta2
  • media_gallery 7.x-1.0-beta3
ricodol’s picture

Thanks for your post !!!!
This version works with me,
thks again
Bruno

Tiktaalik’s picture

#29's zip works for me too - no error messages on upload, multiple drag-and-drop uploads succeed.

I see it's an old Plupload though.

Carnivora’s picture

#29 works like a charm for my drupal7 , too

edg1’s picture

#29 still doesn't work for me.
I must have fucked around to much with the jquery update and plugin.

I was thinking in the direction that i needed a more recent version of jqueery to get it working..
also the plugin is using a JQUERY LOADER PLUGIN where do you have to store these things?

Are the solved by the libraries plugin.
do you need a seperate jquerry upgrade plugin.

Any thoughts??

edg1’s picture

I've tried to install the pecl library uploadprogress but still no luck
I will keep on trying things.

edg1’s picture

FileSize
99.04 KB

I've updated the php5-dev on my debian server to work with the pecl (i also needed to run a apt-get update before i got the right version)
after that i installed the uploadprogress because this wasn't good set and i had a report about is in my reports in drupal
http://perlucida.com/blog/software/howto-install-pecl-uploadprogress-ind...

I updated the jquery using jquery update module
I think after doing a cache refresh all this worked for me

Kind regards @elgandos this sure will safe me tons of time ;-)

I do have some questions and pointers.
Why are we using now a module for jquery upload , a module for library (wich doesn't work for me), a module for jquery plugins.

what i don't understand how can u use the jquery plugin in drupal ?
does any one have some comments here ???

Ryanbach’s picture

Sub.

Ryanbach’s picture

Priority: Major » Critical

Without this you can not upload multiple files correctly, thus the priority should be set to critical.

Ryanbach’s picture

#35 PECL is not needed, upload status is done though JavaScript.

jmsherry’s picture

subscribing

rikclout’s picture

subscribing

Thomas Bosviel’s picture

subscribing

elgandoz’s picture

#29 module does not works for you, guys?!

Thomas Bosviel’s picture

#29 works for me. It seems that major version 1.4.0 breaks compatibility.

David_Rothstein’s picture

FileSize
4.42 KB

Here's a patch that should make the module work with newer versions of the plupload JavaScript library (I tested with 1.4.2, the current latest version).

It turns out there were two changes that affected us here:

  • On the JavaScript side, we were trying to detect that plupload had finished uploading the files by responding to the library's 'UploadProgress' event. It's not clear why that ever worked (if a file is still in the process of being uploaded then kind of by definition it isn't finished uploading yet), but in any case, it stopped working with newer versions of the library. There doesn't appear to be any event we can respond to that's perfectly designed for what we want, but after some trial and error I found that 'StateChanged' appears to work, so this patch switches to that.
  • On the PHP side, we were validating that all temporary files uploaded by plupload ended in a ".tmp" extension, but the library switched its behavior so that the temporary files now use the actual extension that the final file is supposed to have. So this patch fixes that by forcing them back to ".tmp" (alternately we could have changed our file validation, but as explained in the code comments I think it's preferable not to do that).

I've done some light testing of this patch in different browsers and with the various runtimes (HTML4, HTML5, Flash) and it seems to work, but more testing as well as reviews would be highly welcome. We're hoping to put out a new version of the module within the next couple of days.

David_Rothstein’s picture

-      $out = fopen($temp_directory . DIRECTORY_SEPARATOR . $file_name, $chunk == 0 ? "wb" : "ab");
+      $out = fopen($temp_directory . $file_name, $chunk == 0 ? "wb" : "ab");
....
     // Open temp file
-    $out = fopen($temp_directory . DIRECTORY_SEPARATOR . $file_name, $chunk == 0 ? "wb" : "ab");
+    $out = fopen($temp_directory . $file_name, $chunk == 0 ? "wb" : "ab");

By the way, these changes which I included may be an independent bugfix (rather than strictly necessary for the patch), but some people above sounded like they might have been running into issues with the directory names as well, so I included this fix just to be safe.

The directory separator (i.e., '/') was extraneous, since variable_get('plupload_temporary_uri', 'temporary://') already contains all the slashes it needs. I don't think it hurt to have an extra one, but while I was in the code I just went ahead and removed it.

David_Rothstein’s picture

Status: Needs review » Fixed

I'm pretty confident this works, so I decided to commit it. That way we'll be able to get a new release out soon.

http://drupalcode.org/project/plupload.git/commit/0920019

rikclout’s picture

Status: Fixed » Needs review

Awesome David, looks like your latest patch is working excellent here, thanks a lot!

David_Rothstein’s picture

Status: Needs review » Fixed

Great! Thanks for reporting back.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit 0920019 on master, 7.x-2.x, 8.x-1.x by David_Rothstein:
    Issue #953242 by effulgentsia, suedsuedobst, DonZeptero, David_Rothstein...