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

  • Home
  • SEARCH
  • 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 8911875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:03:22+00:00 2026-06-15T04:03:22+00:00

The below code allows me to delete files SOMETIMES. I have checked permissions on

  • 0

The below code allows me to delete files SOMETIMES. I have checked permissions on the files and folders and they exist and are given proper access. Sometimes when I press the remove button; it removes the file and sometimes it simply refreshes the page and nothing happens. Is there anything I can do to make unlink work correctly? Am I missing something in the code below? This is in ZEND.

public function delimageAction()
{
    $request = $this->getRequest();

    if ($request->isPost()) {
        // Get the image name
        $imageName = $request->getParam('file');

        $old = getcwd();
        chdir(APPLICATION_PATH . "/../public/images/blog/"); // Change directory to the files
        fclose(APPLICATION_PATH . "/../public/images/blog/" . $imageName);

        // Delete it
        unlink(APPLICATION_PATH . "/../public/images/blog/" . $imageName)

        chdir($old); // Return to old directory
    }
    $this->_helper->redirector('blog', 'index');
}
  • 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-15T04:03:23+00:00Added an answer on June 15, 2026 at 4:03 am

    Remove the two chdir calls since they serve no purpose, and the fclose which will result in an error. Beyond that you need to check the error log to see what is causing the deletion to fail, it could be permissions related. You could also check the return value for unlink, since it should return false if it doesn’t work.

    As hinted in the comments, there is quite a big security hole in your script as it allows a malicious user to delete any file in your application. You need to sanitise the ‘file’ param to ensure the path supplied is within the public/images/blog/ folder.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code below allows me to find the word error in all my files
I've put together the code below that lists and allows me to delete members.
The code below allows the user to enter in a phrase in plain English,
I have below a code that will plot a sphere, it's proportions are defined
I have a form as below which allows user to select different collar types.
I have the following code that defines a getParts method to find a given
I'm using a ListView and have two buttons that allows users to delete or
logging exception the code below allows to save the content of an exception in
I was wondering how can I allow NULL values in the following code below
Below code not work, but it's work fine for jsf1.2. Now the framework is

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.