Sorry, after a bit of a reread don't forget to record the path of your file somewhere. Either in the database itself or I tend to include it as a constant or attribute of my model so I can move stuff easily.
cheers, mikee On 05/12/06, Mikee Freedom <[EMAIL PROTECTED]> wrote: > Hey Paul, > > File uploads can be tricky sometimes. > > Have you gone through the information found in the PHP manual? > > http://nz.php.net/manual/en/features.file-upload.php > > Some good pointers in there. > > In a nutshell, a file input field is going to be interpreted by PHP as > an array. It is full of data about the file the user has uploaded. Do > a debug() (or good old print_r()) on the $this->data array or even > better on the field that uploads the file. > > You won't be able to get Cake to insert that information straight in > to the database, you're going to have to run some code to process it > first and then update your $this->data array prior to saving. > > What I tend to do is have my file upload as a seperate input field not > attached to the data array. i.e. > > <input name="my_file_upload" type="file" /> > > Then in my controller I look to see whether a file has been uploaded > successfully using: > > $this->params['form']; > > SEE: http://manual.cakephp.org/chapter/controllers > > What I would be looking for in this instance would be > > $this->params['form']['my_file_upload']; > > Then I run my file upload processes i.e. move_uploaded_file() and all > that jazz. If this goes successfully then I update the file_location > field of my model. > > $this->data['MyFileModel']['file-location'] = > $this->params['form']['my_file_upload']['name']; > > and then I can save my model. > > As I said do a debug on : > > $this->params['form']['my_file_upload']; > > and you'll know more about what is going on. > > I've got a file_handler component that I wrote that I will put in to the > pastes: > > http://cakephp.org/pastes/show/56da1a8477e9814a877e64014d3babbf > > Your best reference for this stuff is the PHP manual - absolute gold! > > HTH, > mikee > > On 05/12/06, Websta* <[EMAIL PROTECTED]> wrote: > > > > Ok so i am having some major issues getting file uploads going on my > > cake app. > > > > Firstly what seems to happen is as soon as i add > > 'enctype="multipart/form-data"' to mthe form in my view, > > my call to $this->Model->save($this->data) in the controller spits the > > dummy as the file field is now an array of the related file info > > (tmp_name,name,size etc) and cake spits this at me: > > > > Notice: Array to string conversion in > > /var/users/visionnz/cake/cake/libs/model/datasources/dbo_source.php on > > line 502 > > > > And the sql insert also fails as the file value is now Array as opposed > > to 'filename', so corrupting the sql. > > > > If anyone has any pointers how the hell i get my data to save and also > > if anyone could suggest a good source for a file upload component - i > > have tried a couple neither of wich i got to test properly due to this > > other problem. > > > > Any feedback is much appreciated, i have spent many hours pulling my > > hair out and scouring the net to no avail for a solution to my > > problem!! > > > > Cheers. > > > > Paul. > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---