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.

PHP error using Safecracker / images not deleted from directory

July 29, 2011 7:01pm

Subscribe [6]
  • #1 / Jul 29, 2011 7:01pm

    FarmBoy

    24 posts

    Greetings EE Team,

    My issue could be related to these threads:

    http://ellislab.com/forums/viewthread/192969/

    http://ellislab.com/forums/viewthread/195320/

    I’m using a recently purchased EE 2.2.1 version with the 7-05-11 hotfix, running on a localhost/XAMPP.

    I’m able to upload images using the safecracker file fieldtype.  My problem has to do with deleting them.  After clicking the grey “X” on the image and submitting the form, it appears the image has been deleted.  But the File Manager in the EE Control Panel still shows the image in the directory.  This happens when editing the entry in both the Control Panel and the safecracker form.

    On the pages that include a safecracker form, I’m getting the following error:

    A PHP Error was encountered

    Severity: Notice
    Message:  Use of undefined constant BASE - assumed ‘BASE’
    Filename: libraries/Filemanager.php
    Line Number: 842

    To debug, I replaced all instances of the “BASE” constant with the value set in line 675:
    $this->EE->functions->fetch_site_index(0,0).QUERY_MARKER

    No PHP errors occurred after that, and the JSON seemed to be sent correcly.  But the problem remained - images were not being deleted from the directory.

    Also, I’m loading jquery in my html head tags and using “include_jquery=“no” in my safecracker form.  I tried moving my jquery loading script to my footer but no result.

    Looking forward to your response!

  • #2 / Aug 01, 2011 4:19am

    John Henry Donovan

    12339 posts

    Hi FarmBoy and welcome to the forums:)

    Did you manually apply the hotfix to the EE version or just download a version after the hotfix?
    Because there was an issue where the hotfix was not included in the main download recently so reapplying the hotfix would be a good start here.

    If you already applied the hotfix manually then did you re-save your output and debugging settings?

    Can you share you template code with us please?

  • #3 / Aug 01, 2011 6:27am

    FarmBoy

    24 posts

    Hello John,

    I had already downloaded the hotfix and applied it manually.  And I did re-save the output and debugging settings after applying it.

    My code involves templates within a template. The first is the “account/index” template that acts as my layout file:

    {!-- check for "Pending" member group. --}
    {if logged_in_group_id != '4'}
      
      {if logged_out}
    
        {embed="account/login"}
    
      {if:else}
    
        {embed="account-inc/index" page_title="My Account"}
    
        <body>
        <div id="container">
    
        {global_header}
    
        <div id="wrapper">
    
        <div class="left thin">
          
          {!-- navigation menu --}
          <div id="account-menu">
            
            {if segment_2 == 'listings' && segment_3}
              {embed="account-inc/menu" sub_menu="listings"}
            
            {if:else}
              {embed="account-inc/menu"}
              
            {/if}
                
          </div>
          
        </div>
    
        <div class="right">
          
          {!-- content --}
          <div id="account">
    
          {if segment_2 == 'settings'}
            {embed="account-inc/edit-profile"}
    
          {if:elseif segment_2 == 'listings'}
            
            {!-- OTHER TEMPLATE RENDERED BELOW --}
            {if segment_3 && segment_4} 
              {embed="account-inc/{segment_4}" listing_id="{segment_3}"} 
    
            {if:else}
              {embed="account-inc/listings"} 
    
            {/if}
    
          {if:elseif segment_2 == 'error'}
            {embed="account-inc/error"}
      
          {if:else}
            {embed="account-inc/overview"}
          {/if}
          
          </div>
        </div>
    
        <div class="clear"></div>
    
        {global_footer}
    
        {wrapper_close}
        
        {html_close}
    
      {/if}
      
    {if:else}
      {!-- redirect if "Pending" member group. --}
      {redirect='account/pending'}
    
    {/if}


    Here is the “account-inc/edit-listing-logo” template that includes the safecracker form:

    {embed="account-inc/entry-heading" channel_id="listings"}
    
    {exp:safecracker channel="listings" include_jquery="no" require_entry="yes" entry_id="{segment_3}" return="{segment_1}/{segment_2}/{segment_3}/{segment_4}" author_only="yes"}
      <h2>Edit Logo</h2>
    <p>  <br />
      <div class="field"><br />
        <label for="listing_logo">{label:listing_logo}</label><br />
        <br />
        {!-- safecracker file field --}<br />
        {field:listing_logo} <br />
      </div><br />
      <br />
      {!-- submit buttom --}<br />
      {embed="account-inc/edit-listing-submit-button"}</p>
    
    <p>{/exp:safecracker}

    And here is the “account-inc/entry-heading” template called from above and also includes a safecracker form:

    
    
    

    Thank you for your time.

  • #4 / Aug 03, 2011 2:44pm

    Brandon Jones

    5500 posts

    Hi FarmBoy,

    After editing the entry in the control panel, removing the file and hitting Submit, do you get any errors? Does synchronizing the upload location help?

  • #5 / Aug 03, 2011 7:33pm

    FarmBoy

    24 posts

    Hello Brandon,

    I do not get any PHP errors when I remove the file click Submit using the Control Panel.  However, the file still remains in the directory. The problem still remained after synchronizing the upload location.

    For each web page that includes a safecracker form, the PHP error can been seen in my Firebug Console from Google Chrome, but not on top of the web page.

  • #6 / Aug 05, 2011 11:45am

    Sue Crocker

    26054 posts

    Hi, FarmBoy.

    I wouldn’t necessarily expect removing the file inside the entry to permanently delete the image - what happens if you just had put in the wrong one?

    Are you using EE2.2.2 or EE2.2.1 with this site? I’m able to replicate the inability to remove a file from the SafeCracker form.

  • #7 / Aug 05, 2011 6:07pm

    FarmBoy

    24 posts

    Hi Sue,

    Thanks for your input. I just really expect the file to be removed permanently from the directory, especially if a member uses the Safecracker File fieldtype on the front-end. Otherwise, it seems like coutless files would start piling up. That could be the case if lots of members were contantly adding and deleting images for a large photo gallery.

    If a member accidently deletes the wrong file, they will have to upload the file again. I just think it’s the member’s responsiblity. To minimize those instances, I could add some javascript with a warning message like “really delete my_file.jpg?”.

    I do not plan to allow Control Panel / File Manger access to any members.  But let them change their entries using safecracker forms.

    I’m using EE 2.2.1. Just curious, but were you able to replicate the PHP error also? 

    I’m not sure if the PHP error has anything to do with files not being removed from the directory. But here’s the incorrect response that is passed when the error occurs when using a safecracker form:

    </div>{"uploader":"<div id=\"file_uploader\" class=\"pageContents\">\n\t<iframe name=\"upload_iframe\" src=\"BASE&C=content_files_modal\" frameBorder=\"0\"><\/iframe>\n\t<div class=\"button_bar ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix upload_step_1\">\n\t\t<img >\n\t\t<input type=\"submit\" class=\"before_upload disabled-btn\" name=\"upload_file\" value=\"Upload File\" id=\"upload_file\" \/>\n\t\t<input type=\"submit\" class=\"file_exists submit\" name=\"rename_file\" value=\"Rename File\" id=\"rename_file\" \/>\n\t\t<a >Browse Files<\/a>\n\t\t<a >Edit File<\/a>\n\t\t<input type=\"submit\" class=\"after_upload filebrowser submit\" name=\"edit_file_modal\" value=\"Edit File\" id=\"edit_file_modal\" \/>\n\t\t<input type=\"submit\" class=\"after_upload filebrowser submit\" name=\"choose_file\" value=\"Use Uploaded File\" id=\"choose_file\" \/>\n\t<\/div>\n<\/div>\n\n\n"}

    And I believe this is the correct response, viewed in the File Manager of the Control Panel (same response but no closing div tag at the beginning):

    {"uploader":"<div id=\"file_uploader\" class=\"pageContents\">\n\t<iframe name=\"upload_iframe\" src=\"index.php?S=699ac1c86b031c99b2848d716c916e60b52f3fb9&D=cp&C=content_files_modal\" frameBorder=\"0\"><\/iframe>\n\t<div class=\"button_bar ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix upload_step_1\">\n\t\t<img >\n\t\t<input type=\"submit\" class=\"before_upload disabled-btn\" name=\"upload_file\" value=\"Upload File\" id=\"upload_file\" \/>\n\t\t<input type=\"submit\" class=\"file_exists submit\" name=\"rename_file\" value=\"Rename File\" id=\"rename_file\" \/>\n\t\t<a >Browse Files<\/a>\n\t\t<a >Edit File<\/a>\n\t\t<input type=\"submit\" class=\"after_upload filebrowser submit\" name=\"edit_file_modal\" value=\"Edit File\" id=\"edit_file_modal\" \/>\n\t\t<input type=\"submit\" class=\"after_upload filebrowser submit\" name=\"choose_file\" value=\"Use Uploaded File\" id=\"choose_file\" \/>\n\t<\/div>\n<\/div>\n\n\n"}

    I appreciate everyone’s help.

  • #8 / Aug 08, 2011 3:26pm

    Brandon Jones

    5500 posts

    Hi FarmBoy,

    I think Sue’s correct that removing the images completely would be a feature request right now. SafeCracker used to be a 3rd-party module, but we are working on integrating it further into the EE core.

    Regarding the PHP error, is there a single, simple form (no embedded templates or multiple forms on the same page) where you’re still getting an error?  We need to simplify things a bit to see what might be causing this.

  • #9 / Aug 09, 2011 1:15am

    FarmBoy

    24 posts

    Thanks Sue and Brandon for the info. At leastI know how the Safecracker File works now.  I’ll be sure to add a feature request soon. I now understand the PHP error has nothing to do with the Safecracker File issue discussed above.

    I made a simple safecracker form and found the PHP error occurs when I use the jquery script tag between the <head> tags.  I called jquery directly from the google api and still got the same result.

    If I move the jquery tag to my footer, the PHP error is gone. But then scripts above the footer that rely on jquery stop working - things like matrix and channel videos field types, and jquery scripts I use to chain select elements, etc.  This happens even when I use include_jquery=“no” in safecracker.

    Here is the form I used for debugging:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html >
      
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        {exp:jquery:script_tag}
      </head>
      
      <body>
        
      {exp:safecracker include_jquery="no" channel="testing" return="testing/safecracker-test-add" author_only="yes"}
    
        <label for="title">Title</label><input type="text" name="title" id="title" /></p>
    
        <label for="text_input_1">Some Text</label> <input type="text" name="text_input_1" id="text_input_1" maxlength="{maxlength}" /></p>
    
        <button type="submit" value="Submit">Submit</button>
    
      {/exp:safecracker}
    
      </body>
      
    </html>

    jQuery on the front-end is critical. Any solutions?

  • #10 / Aug 11, 2011 12:15pm

    Sue Crocker

    26054 posts

    Hi, FarmBoy.

    I can’t replicate your issue using regular fields that come with EE, haven’t tried with Matrix yet. Are you using the most recent version?

  • #11 / Aug 12, 2011 2:00am

    FarmBoy

    24 posts

    Hey Sue,

    That’s puzzling.  I just now updated to EE 2.2.2, but same result for everything. Still getting the PHP error.

  • #12 / Aug 12, 2011 12:55pm

    Sue Crocker

    26054 posts

    Is this still with your local install?

  • #13 / Aug 12, 2011 1:45pm

    FarmBoy

    24 posts

    Yes its the recent XAMPP version, 1.7.4

  • #14 / Aug 12, 2011 1:50pm

    Sue Crocker

    26054 posts

    What kind of server is this going to eventually end on? Since I don’t have easy access to a Windows machine for testing.

  • #15 / Aug 12, 2011 1:56pm

    FarmBoy

    24 posts

    When the site is live it will use Apache also, same as xampp.

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

ExpressionEngine News!

#eecms, #events, #releases