Thursday, February 7, 2013

Re: Cakephp download function not working

Do your files have an extension? Are you certain that the view vars
are correct? Instead of setting the view vars directly, create an
array var so that you can debug it.

$params = array(
'id' => $adminProcedure['AdminProcedure']['id'],
// etc.
);


$this->set($params);

die(debug($params)); // or log it

On Thu, Feb 7, 2013 at 1:15 AM, Victor Musvibe <jaahvicky@gmail.com> wrote:
> Hi lowpass
>
> I managed to get the files to be uploaded into the admin_procedures folder
> under my app folder and also insert into my table.The current problem that
> im having now is when i try to download the file. Its giving me 2 errors
>
> C:\xampp\htdocs\intraweb\app\admin_procedures\5113458e-9570-4f22-a1aa-07f483176c8c
> was not found
>
> and
>
> Error: The requested address
> '/intraweb/admin_procedures/download/5113458e-9570-4f22-a1aa-07f483176c8c'
> was not found on this server.
>
> Please not intraweb is the name of my application.
>
> below is my code for the uploadFile and download functions
>
> function uploadFile() {
> $file = $this->request->data['AdminProcedure']['file'];
> if ($file['error'] === UPLOAD_ERR_OK) {
> $id = String::uuid();
> if (move_uploaded_file($file['tmp_name'],
> APP.'admin_procedures'.DS.$id)) {
> $this->request->data['AdminProcedure']['id'] = $id;
> $this->request->data['AdminProcedure']['user_id'] =
> $this->Auth->user('id');
> $this->request->data['AdminProcedure']['filename'] = $file['name'];
> $this->request->data['AdminProcedure']['filesize'] = $file['size'];
> $this->request->data['AdminProcedure']['filemime'] = $file['type'];
> return true;
> }
> }
> return false;
>
> }
>
> function download($id = null) {
> $adminProcedure = $this->AdminProcedure->findById($id);
> $this->viewClass = 'Media';
> $filename = $adminProcedure['AdminProcedure']['filename'];
> $this->set(array(
> 'id' => $adminProcedure['AdminProcedure']['id'],
> 'name' => substr($filename, 0, strrpos($filename, '.')),
> 'extension' => substr(strrchr($filename, '.'), 1),
> 'path' => APP.'admin_procedures'.DS,
>
> 'ext'=>'pdf',
> 'download' => true,
> ));
> }
>
> and here is my view file code where im trying to download the file -
>
> <?php echo $this->Html->link(__('Download', true), array('action' =>
> 'download', $adminProcedure['AdminProcedure']['id'])); ?>
>
>
> On Thu, Feb 7, 2013 at 2:32 AM, lowpass <zijn.digital@gmail.com> wrote:
>>
>> It's not clear what you mean by "when i view the index.ctp manually
>> its not inserting any record in the table". Is a record being added to
>> the DB? If not, post your add() action in full.
>>
>> But before doing that, check that the file is being uploaded.
>>
>> if (!empty($this->request->data))
>> {
>> die(debug($this->request->data)); // or log it
>>
>> Make sure that the form create options include 'type' => 'file' if the
>> file array isn't there.
>>
>> On Wed, Feb 6, 2013 at 3:37 AM, Victor Musvibe <jaahvicky@gmail.com>
>> wrote:
>> > I am struggling with a download functionality for cakephp2.x. Here is
>> > what i
>> > am trying to achieve.
>> >
>> > I am uploading my files to a folder named procedures_uploads after i
>> > upload
>> > the file i should be able to download it.
>> >
>> > Currently when i upload the file from my add.ctp its not redirecting to
>> > the
>> > index.ctp and when i view the index.ctp manually its not inserting any
>> > record in the table . Below is my code for the download functionality
>> > and
>> > the add function
>> >
>> > /** download functionality */
>> >
>> > function download($id = null) {
>> > $adminProcedure = $this->AdminProcedure->findById($id);
>> > $this->viewClass = 'Media';
>> > $filename = $adminProcedure['AdminProcedure']['filename'];
>> > $this->set(array(
>> > 'id' => $adminProcedure['AdminProcedure']['id'],
>> > 'name' => substr($filename, 0,
>> > strrpos($filename,
>> > '.')),
>> > 'extension' => substr(strrchr($filename,
>> > '.'),
>> > 1),
>> > 'path' => APP.'procedures_uploads'.DS,
>> > 'ext'=>'pdf',
>> > 'download' => true,
>> >
>> > )); }
>> >
>> > And this is how i am saving the data in my add function
>> >
>> > if ($this->uploadFile() &&
>> > $this->AdminProcedure->save($this->request->data))
>> >
>> > Does anyone know how to solve this proplem?
>> >
>> > your assistance would be greatly appreciated.
>> >
>> > --
>> > Like Us on FaceBook https://www.facebook.com/CakePHP
>> > Find us on Twitter http://twitter.com/CakePHP
>> >
>> > ---
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "CakePHP" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to cake-php+unsubscribe@googlegroups.com.
>> > To post to this group, send email to cake-php@googlegroups.com.
>> > Visit this group at http://groups.google.com/group/cake-php?hl=en.
>> > For more options, visit https://groups.google.com/groups/opt_out.
>> >
>> >
>>
>> --
>> Like Us on FaceBook https://www.facebook.com/CakePHP
>> Find us on Twitter http://twitter.com/CakePHP
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "CakePHP" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to cake-php+unsubscribe@googlegroups.com.
>> To post to this group, send email to cake-php@googlegroups.com.
>> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cake-php+unsubscribe@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: