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 8856321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:19:48+00:00 2026-06-14T14:19:48+00:00

I am writing a simple application with cakePHP 2.x. I need to allow user

  • 0

I am writing a simple application with cakePHP 2.x. I need to allow user to uplaod and download files. The Upload works fine, but the i’m stuck with the download action.

I have a Controller name Documents, containing the Download action:

public function download($id = null) {
    $this->Document->recursive = -1;
    $doc = $this->Document->find('first', array('conditions' => array('Document.id' => $id)));

    $filename = $doc['Document']['file_file_name'];

    $resp = new CakeResponse();
    $resp->download(Configure::read('upload_dir').'upload'.DS.$id.'_'.$filename);
    $resp->send();
}

Yes I didn’t check if the file exists, etc… but it’s just for testing.
So the path in the download method is something like: /home/www-app/upload/$id_$filename

Of course, the file exists and both paths are equal.

But I got the following error from chrome:

Erreur 6 (net::ERR_FILE_NOT_FOUND) : File or Directory not found

I tried the $resp->file() method but cakePHP seems to not know that method.

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-14T14:19:49+00:00Added an answer on June 14, 2026 at 2:19 pm

    you are not working with Cake2.x and its response class the way you should (and how it is documented!)

    dont use a new instance, there already is one you need to use:

    $this->autoRender = false;
    $this->response->send();
    

    etc.

    also, using autoRender false you dont need a view (what for if you directly send the file?).

    Correction 2013-01-10:
    You dont even need the send(). the autoRender part itself should suffice.
    The response class will then automatically invoke send() at the end of the dispatching process:

    $this->autoRender = false;
    $this->response->file(Configure::read('upload_dir').'upload'.DS.$id.'_'.$filename);
    
    // optionally force download as $name
    $this->response->download($name);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a simple WinForms application in which I allow the user to
I'm writing very simple application. It is supposed to download files from internet. I
I'm writing an simple application for users to upload an image, modify it and
I'm writing a simple application in Python which displays images.I need to implement Zoom
I am writing a simple Tweepy application for fun, but am really limited to
I am writing a fairly simple MVC3 application that allows a user to retrieve
I'm writing a simple web application using CakePHP version 1.2 (the latest) and am
I'm thinking of writing simple application for Windows Mobile devices, where user could simply
Am writing a simple application which can write a to pdf,doc,xls and access files.
I am writing this simple Qt application, but it is showing the following errors.

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.