This is a discussion on Uploaded file within the PHP General forums, part of the PHP Programming Forums category; Hi, How do I pass an uploaded file, from a form, to a class? I have a file type on ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
How do I pass an uploaded file, from a form, to a class? I have a file type on the form called file. The variable $file is fine in my php code, can be used normally. But, I want to pass it to a class then manipulate the file, but it does not work. $cMyClass->fnManipulateFile($file); the function fnManipulateFile gets $file only as the path the file was temporarily uploaded to (tmp/98rsof398) but the other variables are blank, such as $file_name. is it possible to do this? or do I have to pass each one, like $file_name, $file_size, etc.? Thanks, Chris |
|
|||
|
On 4/26/07, PHP <php_list@ibcnetwork.net> wrote:
> Hi, > How do I pass an uploaded file, from a form, to a class? > > I have a file type on the form called file. > > The variable $file is fine in my php code, can be used normally. > > But, I want to pass it to a class then manipulate the file, but it does not work. > > $cMyClass->fnManipulateFile($file); > > the function fnManipulateFile gets $file only as the path the file was temporarily uploaded to (tmp/98rsof398) > but the other variables are blank, such as $file_name. > > is it possible to do this? or do I have to pass each one, like $file_name, $file_size, etc.? > > Thanks, > Chris You should move your uploaded file first with the move_uploaded_file function, and then perform actions on it :) Tijnema |
|
|||
|
PHP wrote:
> How do I pass an uploaded file, from a form, to a class? > > I have a file type on the form called file. > > The variable $file is fine in my php code, can be used normally. > > But, I want to pass it to a class then manipulate the file, but it does not work. > > $cMyClass->fnManipulateFile($file); > > the function fnManipulateFile gets $file only as the path the file was temporarily uploaded to (tmp/98rsof398) > but the other variables are blank, such as $file_name. > > is it possible to do this? or do I have to pass each one, like $file_name, $file_size, etc.? Read this before posting here: http://php.net/features.file-upload [yes, it's called the manual] -Stut |
|
|||
|
2007. 04. 26, csütörtök keltezéssel 11.57-kor PHP ezt Ã*rta:
> Hi, > How do I pass an uploaded file, from a form, to a class? > > I have a file type on the form called file. > > The variable $file is fine in my php code, can be used normally. if you have $file then you are probably using register_globals. don't do that. it's the source of evil. use $_FILES instead > > But, I want to pass it to a class then manipulate the file, but it does not work. > > $cMyClass->fnManipulateFile($file); > > the function fnManipulateFile gets $file only as the path the file was temporarily uploaded to (tmp/98rsof398) > but the other variables are blank, such as $file_name. > > is it possible to do this? or do I have to pass each one, like $file_name, $file_size, etc.? if you use $_FILES you can pass $_FILES['file'] to the function greets Zoltán Németh > > Thanks, > Chris |
|
|||
|
On Thu, April 26, 2007 2:08 pm, Stut wrote:
> PHP wrote: >> How do I pass an uploaded file, from a form, to a class? >> >> I have a file type on the form called file. >> >> The variable $file is fine in my php code, can be used normally. >> >> But, I want to pass it to a class then manipulate the file, but it >> does not work. >> >> $cMyClass->fnManipulateFile($file); I suspect you are doing like this: $file = $_FILES['file']['file_name']; $cMyClass->fnManipulateFile($file); You could do this instead: $file = $_FILES['file']; $cMyClass->fnManipulateFile($file); Now you have an array coming in with all the elements you need, file_name, error, original_name, etc. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? |