Plugin to download cakephp No input parameters can be changed

I just linked this plugin to my cakephp project: https://github.com/josegonzalez/cakephp-upload .

It took me a long time to realize that it was uploading files to webroot \ files \ model_name \ filename, at first I thought the file was not uploaded. The database looks like this:

ID | DESCR | File name | the path to the file

I tried everything to change the input parameters but nothing happened, it copies the file to: webroot \ files \ model_name \ filename over and over. I tried to clear the cache but also didn't work.

 public $actsAs = array(
    'Upload.Upload' => array(
        'path' => '{ROOT}{DS}webroot{DS}img{DS}{model}{DS}{field}{DS}',
        'filename'=> array(

    )
);

      

also:

        public $actsAs = array(
    'Upload.Upload' => array(
        'filename'=> array(
        'path' => '{ROOT}{DS}webroot{DS}img{DS}{model}{DS}{field}{DS}',        
            )
    )
);

      

also:

     class User extends AppModel {
        public $actsAs = array(
            'Upload.Upload' => array(
                'filename' => array(
                    'fields' => array(
                        'dir' => 'photo_dir'
                    )
                )
            )
        );

}

      

At this point, I thought it didn't work at all. So I changed the filename, but I got the sql error, so it should work before that:

'Upload.Upload' => array(
'filename' => array(

      

I spent a lot of time to find a solution (on sof, google all over the place). But I don't know why I can't change the download folder.

Update1: Did a little research:

class UploadBehavior extends ModelBehavior {

public $defaults = array(
    'rootDir' => null,
    'pathMethod' => 'primaryKey',
    'path' => '{ROOT}webroot{DS}files{DS}{model}{DS}{field}{DS}',
..

      

However, I cannot change the path parameter with my model, here I can change it and work well.

+3


source to share


1 answer


The raw php is enough to upload files, just create a form with enctype = "multipart / form-data" containing one or more file type inputs and use the simple php "move_uploaded_file" method to save it to the desired location.

Here's a sample form:

<form action="yourscript.php" method="post" enctype="multipart/form-data">
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload File" name="submit">
</form>

      

And the php method:



move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], 'yourpreferredpath/yourfile')

      

But in CakePhp, instead of $ _FILES, you should use $ this-> request-> data, as this:

$this->request->data["fileToUpload"]["tmp_name"]

      

See http://www.w3schools.com/php/php_file_upload.asp for details

0


source







All Articles