Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7836731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:17:03+00:00 2026-06-02T14:17:03+00:00

EDIT : UPDATING MY QUESTION FOR MORE CLARIFICATION ========================================================== I use MeioUpload to upload

  • 0

EDIT: UPDATING MY QUESTION FOR MORE CLARIFICATION

==========================================================

I use MeioUpload to upload pictures. The picture location is placed in the DB users table in image as such:/img/uploads/users/img/picture34.png.

When a user is deleted, CakePHP is also accessing the physical location of this image from User.image and deleting that image.

There is no belongTo/HasMany relationship here as I do not have an image model/controller.

How can I prevent CakePHP from physically deleting this image?

==========================================================

In my application I have the option to remove a user using the admin_delete function in my users_controller.php. However, when this function is called (see following function), the image saved in the DB is also deleted. How can I prevent this function from removing the image.

function admin_delete($id = null) {

    if (!$id) {
        $this->Session->setFlash(__('Este usuario nao existe', true));
        $this->redirect(array('action'=>'index'));
    }

    if ($this->User->delete($id)) {
        $this->Session->setFlash(__('Este usuario ja foi removido', true));
        $this->redirect(array('action'=>'index'));
    }

    $this->Session->setFlash(__('Este usuario nao foi removido', true));
    $this->redirect(array('action' => 'index'));
}

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:17:19+00:00Added an answer on June 2, 2026 at 2:17 pm

    EDIT

    The Meioupload behavior defines this beforeDelete method:

    /**
     * Deletes all files associated with the record beforing delete it.
     *
     * @author Vinicius Mendes
     * @param $model Object
     */
    function beforeDelete(&$model) {
        $model->read(null, $model->id);
        if(isset($model->data)) {
            foreach($this->__fields as $field=>$options) {
                $file = $model->data[$model->name][$field];
                if($file && $file != $options['default'])
                    $this->_deleteFiles($file, $options['dir']);
            }
        }
        return true;
    }
    

    Since there is no option to don’t delete the image I think the only way is to temporary detach the behavior. Couldn’t test it but something like this could work:

    function admin_delete($id = null) {
        $this->User->Behaviors->disable('MeioUpload');
    
        // your code
    
        $this->User->Behaviors->enable('MeioUpload');
    }
    

    ===

    I’m assuming the image is associated with the user model by a belongsTo/hasMany association? In this case the standard delete method has a parameter to avoid deleting of associated data, here is the definition of the delete function:

    delete(int $id = null, boolean $cascade = true);
    

    if you set cascade to false you associated image doesn’t get deleted:

    if ($this->User->delete($id,false)) {
        $this->Session->setFlash(__('Este usuario ja foi removido', true));
        $this->redirect(array('action'=>'index'));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT 2 I am updating the question again to more simply explain what I
Edit : updating generalized question to reflect actual domain: sport of hockey. The actual
EDIT: Ok so I'm updating this question, to show what I've built as I've
EDIT: I used, finally, inotify. As stefanB says, inotify is the thing to use.
EDIT: OK, I believe the following solutions are valid: Use the jQuery AOP plugin.
EDIT: There's now a doc page on this so this question is irrelevant, also
Ok this is more of general technology/approach question. We have a very simple web
I'm working on updating one of our applications. It must use .NET 2.0. One
I am building an app that can use a user's current location on certain
EDIT: I wasn't sure if this should be a new question or not so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.