Uploaded file

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-26-2007
PHP
 
Posts: n/a
Default Uploaded file

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
Reply With Quote
  #2 (permalink)  
Old 04-26-2007
Tijnema !
 
Posts: n/a
Default Re: [PHP] Uploaded file

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
Reply With Quote
  #3 (permalink)  
Old 04-26-2007
Stut
 
Posts: n/a
Default Re: [PHP] Uploaded file

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
Reply With Quote
  #4 (permalink)  
Old 04-26-2007
Zoltán Németh
 
Posts: n/a
Default Re: [PHP] Uploaded file

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

Reply With Quote
  #5 (permalink)  
Old 04-27-2007
Richard Lynch
 
Posts: n/a
Default Re: [PHP] Uploaded file

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?
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:56 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0