Upload file extension being stripped from .jpeg files
Site is running 1.5.7b and some products have text/file attributes for customers to upload images. On the product page, the files is selected from the desktop and when the product is added to the cart it displays the full file name and extension. On checkout success, the order is written to the orders.products_attributes table, the products_options_values field is written as file-id. (313. instead of 313.jpeg for example) when the uploaded file extension is .jpeg. The file is uploaded in the images/upload folder with the correct name. If the file extension is .jpg it works as expected. I'm struggling to find the cause of this. Can anybody point me in the right direction?
Re: Upload file extension being stripped from .jpeg files
Compare your copy of includes/classes/upload.php to a fresh download from 1.5.7b (your version).
Re: Upload file extension being stripped from .jpeg files
Quote:
Originally Posted by
swguy
Compare your copy of includes/classes/upload.php to a fresh download from 1.5.7b (your version).
They compared fine
Re: Upload file extension being stripped from .jpeg files
I should also add that this code appears to relate to the actual upload and not writing the uploaded file name to the database. No errors are received that it is an invalid file type and the file is written with the correct extension.
Re: Upload file extension being stripped from .jpeg files
OK, how about includes/classes/order.php - any changes?
Re: Upload file extension being stripped from .jpeg files
The only change is to the section building the confirmation email at around line 1018
PHP Code:
$this->products_ordered_html .=
'<tr>' . "\n" .
//RB mod - Product Image
'<td class="product-details" align="left" valign="top" width="30">' . zen_get_products_image($this->products[$i]['id']) . '</td>' . "\n" .
//RB mod - Product Image
Re: Upload file extension being stripped from .jpeg files
Out of curiosity, does the same issue occur with the image file extension of tiff as compared to tif? Both of these file extensions are recognized in a default install for upload extensions. May help identify a factor contributing to stripping jpeg from the information as compared to tiff.
Re: Upload file extension being stripped from .jpeg files
Quote:
Originally Posted by
mc12345678
Out of curiosity, does the same issue occur with the image file extension of tiff as compared to tif? Both of these file extensions are recognized in a default install for upload extensions. May help identify a factor contributing to stripping jpeg from the information as compared to tiff.
I didn't want to do this on the live site since it requires putting completed orders in. I happened to have a clone of the site that is being used to build a new site. It has a fresh database but the files are identical with the exception of the config files. I added a product to the database with a single attribute type file. Interestingly I found that it works correctly. I'm going to do a full comparison of the files from both sites. Hopefully, I'll find some files that are different. If not that kind of points to a database issue. I don't see any structure differences in the orders_products_attributes table though.
Re: Upload file extension being stripped from .jpeg files
Tested in unmodified 1.5.7c with test product 34; used a file with extension "jpeg" as the front image, completed the order, orders_products_attributes.products_options_values field looks correct.
Re: Upload file extension being stripped from .jpeg files
Quote:
Originally Posted by
swguy
Tested in unmodified 1.5.7c with test product 34; used a file with extension "jpeg" as the front image, completed the order, orders_products_attributes.products_options_value field looks correct.
That's similar to what I'm seeing on the clone. The files from both compared as expected. I exported the table, dropped the table on the clone, and imported and emptied to the clone db. Still worked fine. I'm going to import the entire database and see if that causes the problem. Narrowing things down.
Re: Upload file extension being stripped from .jpeg files
The field orders_products_attributes.products_options_values should be TEXT - is it? If not is it possible the value is just getting truncated?
Re: Upload file extension being stripped from .jpeg files
Quote:
Originally Posted by
swguy
The field orders_products_attributes.products_options_values should be TEXT - is it? If not is it possible the value is just getting truncated?
Yes it is text
Re: Upload file extension being stripped from .jpeg files
Is the .jpeg file's filename equally wrong in the "files_uploaded" table?
I suspect the issue may be occurring in this part of the code, in the shopping_cart.php class:
Code:
if ($products_options_file->parse(TEXT_PREFIX . $_POST[UPLOAD_PREFIX . $i])) {
$products_image_extension = substr($products_options_file->filename, strrpos($products_options_file->filename, '.'));
if (zen_is_logged_in()) {
$db->Execute("INSERT INTO " . TABLE_FILES_UPLOADED . " (sesskey, customers_id, files_uploaded_name) VALUES ('" . zen_session_id() . "', " . (int)$_SESSION['customer_id'] . ", '" . zen_db_input($products_options_file->filename) . "')");
} else {
$db->Execute("INSERT INTO " . TABLE_FILES_UPLOADED . " (sesskey, files_uploaded_name) VALUES ('" . zen_session_id() . "', '" . zen_db_input($products_options_file->filename) . "')");
}
$insert_id = $db->Insert_ID();
$real_ids[TEXT_PREFIX . $_POST[UPLOAD_PREFIX . $i]] = $insert_id . ". " . $products_options_file->filename;
$products_options_file->set_filename("$insert_id" . $products_image_extension);
if (!($products_options_file->save())) {
break;
}
} else {
The green lines are related to the files_uploaded table, hence my question above. If that table's entry is fine, then perhaps the issue is happening afterward.
The red line is (I think) where the filename is "set" for the orders_products_attributes entry. But it's still puzzling about the symptom you're reporting.
Do you have any attribute-related customizations/plugins installed?
Re: Upload file extension being stripped from .jpeg files
Quote:
Originally Posted by
DrByte
Is the .jpeg file's filename equally wrong in the "files_uploaded" table?
The filename in that table is VERY incorrect. This is one of the entries 3E8A14F3-629D-4A6A-ADCA-E0B795AABCFB.jpeg. All the others for this file extension are similar.
There are no attribute related customiaztions or plugins.
Re: Upload file extension being stripped from .jpeg files
I did a compare of shopping_cart.php to 1.5.7b. I did find one change
PHP Code:
// appears to confuse products priced by attributes
if ($product->fields['product_is_always_free_shipping'] == '1' or $product->fields['products_virtual'] == '1') {
$shipping_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'],
$attribute_price->fields['options_values_price'], $qty);
//Set these variable to a numeric to eliminate warning debug logs - rb
$freeShippingTotal = intval($freeShippingTotal);
$shipping_attributes_price = intval($shipping_attributes_price);
$freeShippingTotal += $shipping_attributes_price;
}
Re: Upload file extension being stripped from .jpeg files
It seems I may have figured this out. The old database had not been converted from utf8 to utf8mb4. The config file was set to the utf8mb4 charset. I modified the config file to utf8 and tested with the .jpeg extension. It loaded the file and added to the tables correctly. I'll continue to monitor this and will update again if it breaks.
Re: Upload file extension being stripped from .jpeg files
Quote:
Originally Posted by
badarac
It seems I may have figured this out. The old database had not been converted from utf8 to utf8mb4. The config file was set to the utf8mb4 charset. I modified the config file to utf8 and tested with the .jpeg extension. It loaded the file and added to the tables correctly. I'll continue to monitor this and will update again if it breaks.
Is this to also mean that haven't run the convert to utf8mb4 plugin to... well update/convert the database to utf8mb4?
I mean will be interesting to see/know that the craziness no longer happens at all, but... :)
Re: Upload file extension being stripped from .jpeg files
You would be 100% correct in saying that the conversion plugin was not run. OOPS! :cool: