(using csv, but dont think that matters)
* on node/add/node_export upload "test.csv"
* (node import fails or some other appleft a file with that name in temp)
* on node/add/node_export upload "test.csv"

result:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'temporary://test.csv' 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] => 2 [:db_insert_placeholder_1] => node_export1.csv [:db_insert_placeholder_2] => temporary://node_export1.csv [:db_insert_placeholder_3] => text/csv [:db_insert_placeholder_4] => 706 [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_6] => 1308398396 ) in drupal_write_record() (Zeile 6776 von /home/xl/workspace/lange/includes/common.inc).

CommentFileSizeAuthor
#19 Untitled.png15.49 KBsj.suraj
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

geek-merlin’s picture

this might in fact be a file_save_upload() bug, but could not find a matching right now.

geek-merlin’s picture

funny, i can reproduce this every *second* time i upload a file with same name.

!!! even without any import error, so in fact this (from description) is NOT necessary:
* (node import fails or some other appleft a file with that name in temp)

danielb’s picture

I'm not exactly an expert in drupal 7 file handling, any ideas on what is wrong?

danielb’s picture

Status: Active » Postponed (maintainer needs more info)
IanNorton’s picture

I'm having exactly the same problem, the first time I upload an XML (in this case) file the import works perfectly, the second time it is already in the 'file_managed' table, so an error is thrown (see below) - clearing the offending entry from the 'file_managed' table fixes it, likewise, changing the file name also gets around the issue.

I would guess that the would be to clear the 'file_managed' table once the transaction's complete?

'PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'temporary://features_de_0.xml' 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] => 21 [:db_insert_placeholder_1] => features_de.xml [:db_insert_placeholder_2] => temporary://features_de_0.xml [:db_insert_placeholder_3] => application/xml [:db_insert_placeholder_4] => 28437 [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_6] => 1313424822 ) in drupal_write_record() (line 6861 of /Users/iannorton/Sites/teamnonjs/includes/common.inc).'
danielb’s picture

Hmm I wonder whether we can get at that file without using file_save() at all. Otherwise, just delete that one file right after we're done?

IanNorton’s picture

I think the quick fix would be to delete it from file_managed at the end of the process, at this point it's been added as a node so I can't see the need for it to remain in file_managed - I may be wrong on that, but removing it didn't cause me any trouble.

danielb’s picture

Status: Postponed (maintainer needs more info) » Active
danielb’s picture

Title: file upoload error if temp file exists » file upload error if temp file exists
danielb’s picture

Status: Active » Needs review

The might be fixed now, please check the 7.x-3.x dev version releases after this date.

danielb’s picture

Status: Needs review » Fixed

marking as fixed due to lack of further bitching

IanNorton’s picture

Sorry - still does exactly the same,

Whenever the file name is the same as a file previously uploaded the error occurs.

geek-merlin’s picture

Status: Fixed » Active

so still an issue

danielb’s picture

Status: Active » Needs review

I managed to reproduce this error, but I kept getting a lot of other warnings and noticed a few other little issues like the filename not being formatted correctly. I fixed those, and now I'm not getting the error anymore?
I'm repeatedly importing the same node over and over again. I've committed that.

danielb’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

Darkflash’s picture

Issue summary: View changes

Same problem so i reopen the bug.
Drupal version : 7.23

Error message
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'temporary://export_campaign.zip' 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] => export_campaign.zip [:db_insert_placeholder_2] => temporary://export_campaign.zip [:db_insert_placeholder_3] => application/zip [:db_insert_placeholder_4] => 554 [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_6] => 1391078029 ) in drupal_write_record() (line 7166 of /home/gregory/V3D/EqualOne_v19/www/includes/common.inc).

Maybe is it a regression ?

nikolaosinlight’s picture

I just hit this bug on latest Drupal 7.
Drupal version 7.38

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'public://user/photos/tmp/1/7df3h38zabcvjylnyfe3.png' 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] => 0 [:db_insert_placeholder_1] => 7df3h38zabcvjylnyfe3.png [:db_insert_placeholder_2] => public://user/photos/tmp/1/7df3h38zabcvjylnyfe3.png [:db_insert_placeholder_3] => image/png [:db_insert_placeholder_4] => 559959 [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_6] => 1437028927 ) in drupal_write_record() (line 7326 of /sw/company/website/deployment/drupal7/includes/common.inc).

I produced it by re-uploading the file about 5 times. I setup a tmp folder with tmp/[0-9] dirs and normally cleanup the tmp file at the end of the upload however the process is 2 step... step 1 upload the file... step 2 crop the file, save new version and clear temp.

So if someone uploads a file on step 1... and then at step 2 goes back and uploads the same file... they will eventually hit this bug. I say eventually because it does not happen as often as one would expect (it appears to be intermittent).

My code is as follows:

$photo_tmp_file = file_save_upload('photo_file', $validators, $photo_tmp_filepath, FILE_EXISTS_RENAME);

Since FILE_EXISTS_RENAME is being passed in then the expectation is that the uploaded file will be renamed if the munged file is the same as an existing file. However that is not what appears to have happened.

UPDATE:

Just did some research and looked through the:

file_save_upload
-> calls file_destination($destination, FILE_EXISTS_RENAME)
-> calls file_create_filename($basename, $directory) (to create a unique file name)
-> calls file_exists($destination)

In looking at file_exists it is purported by someone to return FALSE for streams!
http://php.net/manual/en/function.file-exists.php

pgl at yoyo dot org 5 years ago
Note that this will return false for streams, eg, php://stdin.

sj.suraj’s picture

FileSize
15.49 KB

hey
please help me for multiple file upload with ajax as it is done in this form. I want the same one. Please help me for this.