ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

[Solved] Cannot Output Full Upload Path for File Uploads

May 18, 2012 2:30pm

Subscribe [1]
  • #1 / May 18, 2012 2:30pm

    Jarrett Barnett

    31 posts

    Greetings!

    I’ve been struggling with fixing this problem for some time now…

    I cannot get the full image path to output on either the “Edit Entry” page or any “Template” page.

    To keep it simple, I have a custom field with a shortname of: product_image

    It’s using filedir_1 which is configured like this:
    • Server Path: /var/www/vhosts/website.com/httpdocs/uploads/products/
    • URL: http://www.website.com/uploads/products/

    • Both directories (uploads and products) are set to 777.
    • I am not using MSM.
    • the system folder is BELOW the root.
    • I’m using the latest and greatest EE 2.5.0


    File Field Outputting:

    ———————————————————————————————————————————
    1. Outputting the variable:

    {product_image}

    produces:

    <!-- empty -->

    ———————————————————————————————————————————

    2. Outputting the variable:

    {product_image:large}

    produces:

    _large/myimage.jpg


    ———————————————————————————————————————————

    3. Outputting the variable pair:

    {product_image}
      {filename} | {extension} | {url}
    {/product_image}

    produces:

    myimage | jpg | myimage.jpg

     

    ———————————————————————————————————————————

    Now, this wouldn’t be that big of a deal as I could simply manually hardcode the directory path in the template; HOWEVER, after the image has been uploaded and saved to an entry in the control panel, you cannot resave that specific entry WITHOUT the image being removed from the field and receiving an error saying:

    You do not have access to the directory specified for this field

    The reason this is happening is because the “Edit Entry” page is only outputting:

    _thumbs/myimage.jpg

    which obviously in itself is a broken path. It should be:

    /uploads/products/_thumbs/myimage.jpg


    So to get around this, the client would have to re-select the image (for every File field) anytime they make a change to the page; otherwise, the image is removed automatically.

    ———————————————————————————————————————————

    Looking at the database table:

    _files:
    upload_location_id: 1
    rel_path: /var/www/vhosts/website.com/uploads/products/myimage.jpg
    mime_type:image/jpeg
    file_name: myimage.jpg

    _upload_prefs:
    id: 1
    site_id: 1
    name: Product Images
    server_path: /var/www/vhosts/website.com/httpdocs/uploads/products/
    url: http://www.website.com/uploads/products/
    allowed_types: img
    cat_group: 2|1|3

    _channel_data:
    entry_id: 10
    site_id: 1
    channel_id: 3

    field_id_12: myimage.jpg

    _channel_fields
    id: 12
    site_id: 1
    field_name: product_image
    field_type: file
    field_content_type: image


    ———————————————————————————————————————————
    I’ve tried the following to troubleshoot:

    • overriding the upload directories via the config.php file
    • upgrading from 2.4.0 to 2.5.0
    • reinstalling ExpressionEngine 2.5.0
    • using a relevant URL path in the file upload settings as well as a full URL path.
    • reinstalling the /ExpressionEngine/libraries/File_field.php
    • reinstalling the /ExpressionEngine/libraries/File_integrity.php

  • #2 / May 18, 2012 3:07pm

    Jarrett Barnett

    31 posts

    (EE support, please reference to username: mc2design for our active licenses)

  • #3 / May 18, 2012 3:43pm

    Jarrett Barnett

    31 posts

    Started digging into the File_field.php and outputting the arrays.

    If I print_r the $manipulations I get:

    Array
    (
        [0] => Array
            (
                [id] => 1
                [upload_location_id] => 1
                [title] => thumbnail
                [short_name] => thumbnail
                [resize_type] => constrain
                [width] => 50
                [height] => 50
                [watermark_id] => 0
                [site_id] => 1
            )
    
        [1] => Array
            (
                [id] => 2
                [upload_location_id] => 1
                [title] => standard
                [short_name] => standard
                [resize_type] => constrain
                [width] => 350
                [height] => 350
                [watermark_id] => 0
                [site_id] => 1
            )
    
        [2] => Array
            (
                [id] => 3
                [upload_location_id] => 1
                [title] => large
                [short_name] => large
                [resize_type] => constrain
                [width] => 600
                [height] => 600
                [watermark_id] => 0
                [site_id] => 1
            )
    
    )

    which is correct.


    However, if I print_r $file (right before the return):

    Array
    (
        [url] => myimage.jpg
        [file_name] => myimage.jpg
        [extension] => jpg
        [path] => 
        [upload_location_id] => 
        [file_hw_original] => 
        [raw_output] => myimage.jpg
        [filename] => myimage
        [width] => 
        [height] => 
        [url:large] => _large/myimage.jpg
    )

    Notice how the upload_location_id has gone extinct?

    Will keep digging. Any suggestions are appreciated. Thanks!

  • #4 / May 18, 2012 3:56pm

    Jarrett Barnett

    31 posts

    Hardcoded the upload_location_id into the empty $file array (line 466) and it produced the correct full paths:

    Array
    (
        [url] => <a href="http://website.com/uploads/products/myimage.jpg">http://website.com/uploads/products/myimage.jpg</a>
        [file_name] => myimage.jpg
        [extension] => jpg
        [path] => <a href="http://website.com/uploads/products/">http://website.com/uploads/products/</a>
        [upload_location_id] => 1
        [file_hw_original] => 
        [raw_output] => myimage.jpg
        [filename] => myimage
        [width] => 
        [height] => 
        [url:large] => <a href="http://website.com/uploads/products/_large/myimage.jpg">http://website.com/uploads/products/_large/myimage.jpg</a>
    )

    It appears the IF (line 440) and the ELSE IF (line 449) statements are not working properly and thus leaving the $file variable empty; from which the IF statement on line 460 triggers as legacy support for category images using full image paths.

  • #5 / May 18, 2012 6:59pm

    Jarrett Barnett

    31 posts

    SOLVED. It had to do with how the file is saved to the entry. I found that the database was not saving the image name as:

    https://ellislab.com/asset/images/team-photo/myimage.jpg

    So after that I was able to determine that it could be the Javascript for the file upload which of course is stored in the /themes/ folder. I replaced the /themes/ folder with the latest copy and it solved the problem.

    Hope this helps someone!

  • #6 / May 21, 2012 12:26pm

    Dan Decker

    7338 posts

    Hi Jarrett,

    Wow - first - sorry of for the delay in response. Second - bravo on the details and sleuthing!

    I’m glad you were able to whittle it down to /themes - that seems to get overlooked in the update process. It also seems to be the files most likely to be corrupted during FTP.

    If you need anything else, just let us know.

    Cheers!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases