Php upload file

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Steff
New php-forum User
New php-forum User
Posts: 16
Joined: Thu Sep 04, 2003 1:31 am

Php upload file

Postby Steff » Thu Sep 04, 2003 1:39 am

:?:

Hello

I try to upload file but ...

Here my form :

<form method="post" enctype="multipart/form-data" action="uploadtst.php">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000">
<input type="file" name="userfile">
<input type="submit">
</form>

in this part of code

<?
if (is_uploaded_file($userfile)) {
move_uploaded_file($userfile, "/place/file.new");
}
?>
I never reach into the if condition and so I can't make the move.
Can you help me ?

Thanks
Cordially
Stéphane Vauclaire

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Thu Sep 04, 2003 3:17 am

is_uploaded_file is vaguely deprecating in favour of the reg_globs OFF and $_FILES array manner of addressing variables

if($_FILES['userfile']['error'] == 0)
{
// we have an upload
// usable vars
echo '
'temporary file name = ' .$_FILES['userfile']['tmp_name']. '<br />
'file size = ' .$_FILES['userfile']['size']. '<br />
'client original file name = ' .$_FILES['userfile']['name']. '<br />
'file type - from headers = ' .$_FILES['userfile']['type'];
}

so

move_uploaded_file($_FILES['userfile']['tmp_name'], 'place/file.new');

should be ok

note: ['error'] returns values from 0 to 4 where zero is success

Steff
New php-forum User
New php-forum User
Posts: 16
Joined: Thu Sep 04, 2003 1:31 am

upload file

Postby Steff » Thu Sep 04, 2003 4:13 am

Hello

It can't work when I wrote

Code: Select all

echo $_FILES['userfile']['error'];


It answers 2.

Can you tell me more ?

Thanks
Cordially
Steff

sigix
php-forum Active User
php-forum Active User
Posts: 364
Joined: Mon Jul 14, 2003 9:39 pm
Location: /Earth/Xion

Postby sigix » Thu Sep 04, 2003 4:35 am

look for the file upload articles on phpbuilder .com webmonkey.com and hotscripts.com
and the manual
,,.... :arrow:

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Thu Sep 04, 2003 12:30 pm

UPLOAD_ERR_OK

Value: 0; There is no error, the file uploaded with success.
UPLOAD_ERR_INI_SIZE

Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
UPLOAD_ERR_FORM_SIZE

Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form.
UPLOAD_ERR_PARTIAL

Value: 3; The uploaded file was only partially uploaded.
UPLOAD_ERR_NO_FILE

Value: 4; No file was uploaded.

Note: These became PHP constants in PHP 4.3.0

Read http://uk.php.net/manual/en/features.file-upload.php

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Re: Php upload file

Postby WiZARD » Tue Sep 09, 2003 3:10 am

hi!
try to change some code like this:

Code: Select all

<?
if (is_uploaded_file($userfile)) {
  move_uploaded_file($userfile, '/place/file.new');
}
?>

then you use manipulation of files to you need use once quotes not double PHP understand "filename" like string, not like path to file.....
by the way in include too same.......


Return to “PHP coding => General”

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest