Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
plupload module lets us configure the server directory where temporary files will be stored via:
- plupload_temporary_uri variable in d7.
- plupload.settings -> temporary_uri config value in d8.
In both cases it defaults to temporary:// PHP stream wrapper, but for some values it doesn't work as expected:
- A stream wrapper without trailing slash: Specified directory is not used but its parent. File upload works fine.
- A stream wrapper with trailing slash: Works as expected.
- A directory path without trailing slash: Same as 1.
- A directory path with trailing slash: Specified directory is not used but its parent when writing. File upload fails because reading in the child directory.
Comments
Comment #1
slashrsm CreditAttribution: slashrsm commentedCannot reproduce this. You probably have some other problems.
Comment #2
juampynr CreditAttribution: juampynr commentedThe problem is that if variable plupload_temporary_uri has a path instead of a file stream, file_prepare_directory() gets rid of the trailing slash, so when later on the code does fopen(), it fails since there is no slash between $temp_directory and $file_name.
This code in includes/file.inc converts /tmp/ into /tmp. Note that $directory is passed by reference.
Attached is a patch that I tested with both a path and a stream wrapper.
Comment #3
vishy_singhal CreditAttribution: vishy_singhal commented@jaumy - That does not work either.
I have tried taking a deeper look at this. The exception message while trying to upload files with 1.png, 2.png, 3.png is the following
'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'public://uploads/1/2_0.jpg' for key 'uri'' in main/www/includes/database/database.inc:2168
I tried the following method which worked. Modified main/www/includes/database/database.inc line 2168 to
I am not sure if the above is a good way to solve the problem. A very temporary fix that I am not comfortable with.
Comment #4
adammalone@vishy_singhal I'm not sure that's the root cause of this issue and certainly not worth modifying database.inc for.
@slashrsm I've been able to repro this on a HA environment using the plupload_temporary_uri to point to an alternate path for plupload files.
File /path/to/temp/filesp187kdg91hfjsik8n941a7b111spq1.tmp could not be copied because it does not exist.
This points to a particular issue within plupload where the slash is removed from the temporary path as juampy says in #2
Comment #5
juampynr CreditAttribution: juampynr commentedHere is an updated version where I am fixing another part of the logic which causes the same issue. I will post testing instructions in the next comment.
Comment #6
juampynr CreditAttribution: juampynr commentedThis change makes sure that even though plupload_temporary_uri has a values like /tmp (note there is no trailing slash), we do add it in order to build a full path to an uploaded file such as /tmp/foo.jpg.
This change addresses the fact that file_prepare_directory() removes the trailing slash from a path like /tmp/.
Comment #7
juampynr CreditAttribution: juampynr commentedOops, used the wrong field to change the title.
Comment #8
vishy_singhal CreditAttribution: vishy_singhal commentedNot fixed, Did it work for you?
Comment #9
juampynr CreditAttribution: juampynr commentedYes @vishy_singhal.
Comment #10
vishy_singhal CreditAttribution: vishy_singhal commented@juampy Let me try again with various other combinations
Comment #11
vishy_singhal CreditAttribution: vishy_singhal commented@juampy - rechecking, did you use the same patch as #5 or did you do any other changes?
Comment #12
juampynr CreditAttribution: juampynr commented@vishy_singhal, yes, I used the patch at #5.
Comment #13
vishy_singhal CreditAttribution: vishy_singhal commented@juampy - The problem still exists. Try doing the following
upload file names 0.jpg, 1.jpg, 2.jpg
Once you have successfully uploaded, try uploading them again.
Expected result - the files should be renamed to 0-1.jpg, 1-1.jpg and so on.
Actual result - Plupload fails to upload throwing php error
@Juampy - have you tried this?
Comment #14
juampynr CreditAttribution: juampynr commentedI am sorry @vishy_singhal, I cann't test this issue more. Already had a problem and gave solution to it.
Comment #15
jbloomfield CreditAttribution: jbloomfield commentedThis issue still exists in the latest dev and stable releases. I applied the patch from @juampynr from comment #5 and this fixes the issue. Can this patch be applied to the dev release?
Comment #16
leolandotan CreditAttribution: leolandotan as a volunteer and at Promet Source commentedI'm experiencing this issue too and specifically getting the error:
What's weird is that when I try to upload 1 or 2 images, it passes but when I upload like 7 images about 800KB plus I get the said error.
I'm also using Pantheon as my host and the test/staging site is fine while production has the error. Also I checked my temporary directory value and it's formed as /srv/bindings/some-hash-here/tmp so there's not trailing slash.
Any ideas on why this inconsistency is happening?
Comment #17
budalokko CreditAttribution: budalokko commentedPatch in #5 by juampynr doesn't work for a plupload_temporary_uri in the form of a PHP stream without a trailing slash like this:
temporary://plupload-temp
While reviewing the patch, I found that current module is not really working as expected in this situation: when plupload_temporary_uri is a PHP stream without a trailing slash.
It works, but the used temp file is not stored in the correct directory: directory and file name are concatenated resulting in things like:
temporary://plupload-tempo_1bc3ntv2s1pknqb316bu15lp14i6a.tmp
This second problem happens exactly in the same piece of code we are talking about so I think they are too related to solve them separately.
Attached patch solves the problem in a consistent way for all kind of value for plupload_temporary_uri:
It could have been solved in the opposite way maybe with a bit less of code, but looking at file_stream_wrapper_uri_normalize and file_prepare_directory it seems uris not having trailing slashes are more aligned with core than having them.
Comment #18
budalokko CreditAttribution: budalokko commentedAnd this is the patch for 8.x-2.x branch, which has exactly the same problem.
Updated issue summary because it doesn't reflect the problem we are currently solving.
Comment #19
dalinConfirmed that the patch in #17 works great. I can't comment about D8 though, otherwise I'd mark this RTBC.
Comment #20
steveoriolHello,
For me on D8, I still have links on temporary files, even with patch # 18
I do not know what to try to make the plupload module work :-(
Comment #21
martin.davidson CreditAttribution: martin.davidson commented#17 works great.