Error Handling on File Upload (Author Submission Step2)

Are you responsible for making OCS work -- installing, upgrading, migrating or troubleshooting? Do you think you've found a bug? Post in this forum.

Moderators: jmacgreg, michael, John

Forum rules
The Public Knowledge Project Support Forum is moving to

This forum will be maintained permanently as an archived historical resource, but all new questions should be added to the new forum. Questions will no longer be monitored on this old forum after March 30, 2015.
Posts: 4
Joined: Fri May 20, 2011 5:38 am

Error Handling on File Upload (Author Submission Step2)

Postby eagleeye » Fri Aug 19, 2011 11:10 pm

In my conference, I do not want to have the same papers uploaded more than once.
Here's what i've done so far:

- in the table 'paper_files', I have set the 'original_file_name' column to be UNIQUE
- in AuthorSubmitStep2Form.php, I have added this line (so that when there is a file uploaded for a second time, I would see Step 2 of Author Submission loaded again with an error message) :

Code: Select all

$this->addCheck(new FormValidatorCustom($this, 'submissionFile', 'required', 'author.submit.form.titleExists', array(DAORegistry::getDAO('PaperFileDAO'), 'paperFileExists'), array(), true));

- also i have added this function to PaperFileDAO.php :

Code: Select all

   function paperFileExists($originalFileName, $fileId = null, $allowDisabled = true) {
   $result =& $this->retrieve(
         'SELECT COUNT(*) FROM paper_files WHERE original_file_name = ?' . (isset($userId) ? ' AND file_id != ?' : '') . ($allowDisabled?'':' AND disabled = 0'),
         isset($fileId) ? array($originalFileName, (int) $fileId) : array($originalFileName)
      $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;


      return $returner;

But I still cannot return to Step 2 of Submission process when there is such error.
The page i get, is a page with only this error message on:
DB Error: Duplicate Entry for "xxxx.doc" for key 2.

Have I done all the required things?
Anyone know what else i need to do?

Posts: 952
Joined: Mon May 05, 2008 10:29 am
Location: Vancouver, BC

Re: Error Handling on File Upload (Author Submission Step2)

Postby mcrider » Mon Aug 29, 2011 1:28 pm

Hi eagleeye,

You should do a var_dump on the $originalFileName parameter -- I'm not sure what you have getting passed to your paperFileExists method is actually the original file name. You might have to grab the name of the file being uploaded from the $_FILES global array. In general, your code looks fine, but you'll have to do a bit of debugging in your validation method to see whats actually going on.


Return to “OCS Technical Support”

Who is online

Users browsing this forum: No registered users and 1 guest