Hi
i m trying to save a file pdf to a location :
xampp\htdocs\cake\app\webroot\files or any where in my pc
i have this code...

public function upolad() {
            $filename = '';
            if ($this->request->is('post')) { // checks for the post values
        $uploadData = $this->data['Pod']['pod'];
                if ( $uploadData['size'] == 0 || $uploadData['error'] !== 0) { // checks for the errors and size of the uploaded file
                    return false;
                }
                $filename = basename($uploadData['name']); // gets the base name of the uploaded file

                $uploadFolder = WWW_ROOT . 'files' .DS.$filename;  // path where the uploaded file has to be saved
                $filename = time() .'_'. $filename; // adding time stamp for the uploaded image for uniqueness
                $uploadPath =  $uploadFolder . DS . $filename;
                if( !file_exists($uploadFolder) ){
                    mkdir($uploadFolder); // creates folder if  not found
                }
                if (!move_uploaded_file($uploadData['tmp_name'], $uploadPath)) {
                    return false;
                }

            }
           $this->set('image',$filename);

    }

and my form is

<div class="pods form">
<?php echo $this->Form->create('upload'); ?>
    <fieldset>
        <legend><?php echo __('Add Pod'); ?></legend>

    <?php
        $options = array(

    'Y' => 'Query completed',
    'N' => 'Not Completed'
);

        echo "<table><tr><td>".$this->Form->input('docket_no',array('label'=>'Docket No','class'=>'txtArea1'))."</td>";
        echo "<td>".$this->Form->input('po_no',array('lable'=>'Pod No','class'=>'txtArea1'))."</td></tr>";
        echo "<tr><td>".$this->Form->input('date_of_docket',array('label'=>'Date Docket','dateFormat' => 'DMY'))."</td>";
        echo "<td>".$this->Form->input('acnopen_id',array('label'=>'Account'))."</td></tr>";
        echo "<tr><td>".$this->Form->input('req_ref',array('label'=>'Request Ref','class'=>'txtArea1'))."</td>";
        echo "<td>".$this->Form->input('requester',array('label'=>'Requester','class'=>'txtArea2'))."</td></tr>";
        echo "<tr><td>".$this->Form->input('req_date',array('label'=>'Request Date','dateFormat' => 'DMY'))."</td>";
        echo "<td>".$this->Form->input('pod',array('label'=>'Pod','type'=>'file','class'=>'txtArea2'))."</td></tr>";
        echo "<tr><td>".$this->Form->input('route',array('label'=>'Route','class'=>'txtArea1'))."</td>";
        echo "<td>".$this->Form->input('salesman',array('label'=>'Salesman','class'=>'txtArea1'))."</td></tr>";
        echo "<tr><td>".$this->Form->input('problem_id',array('label'=>'Problem'))."</td>";

        echo "<tr><td>".$this->Form->input('date_sent',array('label'=>'Date sent','dateFormat' => 'DMY'))."</td>";
        echo "<td>".$this->Form->input('query_complete',array(
                               'type'      =>  'select',

                               'options'   =>  $options,
                               'label'    =>   'Query Complete' ))."</td></tr>";
        echo "<tr><td>".$this->Form->input('value',array('label'=>'Value','class'=>'txtArea1'))."</td></tr>";
        echo "<tr><td>".$this->Form->input('notes',array('label'=>'Notes','class'=>'txtArea'))."</td></tr></table>";
    ?>
    </fieldset>
<?php echo $this->Form->end(__('Submit')); 

any help pls

Recommended Answers

All 3 Replies

So, a part the name of the function that is wrong upolad() instead of upload() what's the problem with your script?

Hi
i changed the name of the function
the problem is i cannot save the data

'pod' => array(
    'extension' => array(
        'rule' => array('extension', array('pdf')),
        'message' => 'Only pdf files',
         ),
     'upload-file' => array(
        'rule' => array('uploadFile'),
        'message' => 'Error uploading file'
         ),
),

i have this error
The pod could not be saved. Please, try again.

Do you get any other specific error apart that? Have you checked CakePHP log files?

At line 10 of your script you wrote:

$uploadFolder = WWW_ROOT . 'files' .DS.$filename;

What's the value of WWW_ROOT? Check if there is a slash at the end, otherwise add DS:

$uploadFolder = WWW_ROOT . DS . 'files' . DS . $filename;

Also check if files directory is writable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.