Magento 1.9.0.1更新后后台无法上传新产品图片
Alright, let's break down your problem and walk through actionable fixes step by step:
Quick Recap of Your Scenario
- You fixed the initial
cannot read property 'checked' of undefinederror by modifyinggallery.phtml - Post-fix: Images successfully upload to the
tmpfolder, Ajax returns 200 OK, no console errors—but images don't show up in the gallery or save to the database - Tried switching to Dull Uploader with no improvement
Potential Causes & Fixes
1. Validate Gallery Initialization Data
The core gallery initialization line you shared is critical—let's make sure its data is valid:
var <?php echo $_block->getJsObjectName(); ?> = new Product.Gallery('<?php echo $_block->getHtmlId() ?>', <?php echo $_block->getImageTypesJson() ?>);
- Check
getImageTypesJson()output: Temporarily add<?php var_dump($_block->getImageTypesJson()); ?>togallery.phtmlto see if it returns valid, non-empty JSON. Corrupted or missing image type data (Base/Small/Thumbnail) will break the gallery's ability to register uploaded images.- If it's malformed/empty, verify your product attribute set has the standard image attributes assigned and enabled.
2. Inspect Ajax Request Metadata
Even if the file hits tmp, the gallery might not be sending required data to link it to your product:
- Open your browser's Network tab, trigger an upload, and check the
uploadrequest parameters:- Ensure
form_key,product(product ID), andtmp_nameare all present. - If
form_keyis missing, add it explicitly to the upload form data ingallery.phtml:formData.append('form_key', window.FORM_KEY); - A missing product ID means the system can't associate the temp image with your product—double-check that the product ID is being passed correctly from the page.
- Ensure
3. Verify Permissions Beyond Uploader.php
You checked Uploader.php, but let's cover other critical directories:
- Ensure
pub/media/catalog/product(and all subfolders) has write permissions for your web server user (usuallywww-data,apache, ornginx). - Temporarily set the
tmpupload folder to777to rule out permission blocks (lock it back to755once confirmed). - Confirm the web server user owns these directories with:
chown -R www-data:www-data pub/media/catalog/product
4. Check for Accidental JS Corruption in gallery.phtml
Since you modified this file, compare your version to a fresh Magento core gallery.phtml to spot missing/altered code:
- Pay close attention to sections handling post-upload image registration—even a missing comma or misplaced function call can break the gallery's ability to render and save images.
- Ensure the
Product.Galleryconstructor receives all required parameters (the second argument for image types is non-negotiable).
5. Debug Database EAV Entries
If temp files exist but no DB entries are created, check your product's media gallery data:
- Run this SQL query (replace
[PRODUCT_ID]with your product's ID):SELECT * FROM catalog_product_entity_media_gallery WHERE entity_id = [PRODUCT_ID];- If no rows return, the issue is in the code that inserts into this table—debug the
saveMediaGallerymethod in your product model.
- If no rows return, the issue is in the code that inserts into this table—debug the
- Also verify that image attributes (
image,small_image,thumbnail) are set to "Visible on Product View Page" and "Used in Product Listing" in your attribute settings.
Final Quick Test
Try creating a brand new product and uploading an image to it. If that works, your original product likely has corrupted data. If it still fails, the problem lies in your global gallery/upload configuration.
内容的提问来源于stack exchange,提问作者Ravi Singh

