1) CCK 5.x-1.10
2) ImageField 5.x-2.2
3) 755 permission, www-data owner for files/ directory; 777, root for tmp/ directory
4) private download method
5) configuration (all that matters):
Permitted upload file extensions: jpg jpeg png gif
6) I expect to be able to upload all 4 types of files (jpg jpeg png gif)
7) I can only upload the first file type (jpg). A javascript alert box appears when trying to upload jpeg, png or gif files.
8) Create new content type
Create imagefield cck field with the 4 file types above
Create new node, try to upload picture with extension jpeg, png, gif
An alert box is displayed saying you can't upload the image.

I have investigated this problem and found that it is caused by a non-global javascript replace function. The function call on line 14 of imagefield.js

accept = this.accept.replace(',','|');

only replaces the first comma (the one separating jpg and jpeg). Taking the configuration above, the value of accept would be set to 'jpg|jpeg,png,gif'. It should be 'jpg|jpeg|png|gif'. The correct replace function is

accept = this.accept.replace(/\,/g,'|');

Comments

pathfinderelite’s picture

Status: Active » Needs review
StatusFileSize
new473 bytes

Here is a patch.

drewish’s picture

Status: Needs review » Needs work

it actually needs to consume whitespace between the extensions as well. i think the 6.x code does this.

nath’s picture

Seems to work for me though.

asugene’s picture

StatusFileSize
new25.69 KB

Yes I get the same problem. I have attached the same error message. I do not have this problem in the 5.x-2.1 version. Only in the upgrade version of 5.x-2.2. Tested it on two sites on two different servers and two different browsers.

drewish’s picture

try the -dev version out. it's got some code to fix this already.

drewish’s picture

actually, if you're using filefield, update that too: http://drupal.org/node/355195

drewish’s picture

marked #328205: Accepted filetypes not allowed to be uploaded by Firefox as a duplicate since this has a patch.

arsart’s picture

Hi all,

Doesn't work for me on -dev version :(

lelizondo’s picture

Version: 5.x-2.2 » 5.x-2.x-dev

It's not working for me either.

jbc’s picture

Version: 5.x-2.x-dev » 5.x-2.2

Experiencing same issue. Will test with dev version asap.

Boletus’s picture

Version: 5.x-2.2 » 5.x-2.x-dev

tried to upgrade to the the 5.2-dev version to get rid of the file type bug. Got a:

Fatal error: Call to undefined function _content_admin_display_contexts() in /home/mydomain.com/public_html/shop2/sites/all/modules/imagefield/imagefield.install on line 81.
Drupal halted the install.

Uploaded the 5.2.2 version again and run update.php. Got a two errors:

array_merge() [function.array-merge]: Argument #2 is not an array in /home/mydomain.com/public_html/shop2/update.php on line 309.

Invalid argument supplied for foreach() in /home/mydomain.com/public_html/shop2/update.php on line 542.

v1nce’s picture

Version: 5.x-2.x-dev » 5.x-2.2
Priority: Normal » Critical
Status: Needs work » Needs review
StatusFileSize
new634 bytes

The attached patch fixes this issue and uses exact code from filefield.js (filefield module 5.x-2.4).

svihel’s picture

I tested the imagefield-regex.patch patch and it didn't work for me. Should I do any more then replace the code and refresh the site?

jhung’s picture

For those not willing to wait for an official patch, replacing line 14 with the recommendation in the original post fixes this problem for me.

lelizondo’s picture

can you tell us exactly what the new line will look like? thanks

drewish’s picture

Status: Needs review » Closed (duplicate)

see #357903: JavaScript on Imagefield won't upload image files for essentially the same patch with tiny improvement in formatting.

codenamerhubarb’s picture

Thanks pathfinderelite, that seems to have fixed my problem.