Re: Uploading files

From: Date: Sun, 20 May 2001 21:35:12 +0000
Subject: Re: Uploading files
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-53632@lists.php.net to get a copy of this message
Hello Diego, You need to use copy() If the form input is like this: file: <input name="userfile" type="file"> <input type="submit" Then PHP will assign a few variables automatically to the file, which include: $file_name - actual name of the file (pic.jpg) $file_size - size in bytes of the file $file_type - MIME type of the file. This: <input type="hidden" name="MAX_FILE_SIZE" value="1000">Send this Will only let you upload a file of less than 1kb if you program around that (1024 bytes in a Kb). Setting to 102400 would give you a max upload size of 100 Kb. So, simply: <? if ($file_size < $MAX_FILE_SIZE) { @copy($file, "/path/to/dir/" . $file_name) or die ("Something's up."); } else { echo "Sorry. Your file was bigger than the allowed size of " . round(($MAX_FILE_SIZE / 1024), 2) ."Kb. Please go back and try again."; } ?> You can of course test whether the file being uploaded is a type you want, like "image/jpeg" from the $file_type. Hope this helps. James. "Diego Pérez Rández" <webzitos@terra.es> wrote in message news:3B079408.43D28BEA@terra.es... > > Hi to all: > > I don`t konw very well php. I do examples everyday and solve some > problems. But in other i need help. > > Today i want to upload a file. I have the form that you can find in > the php manual. > > <form enctype="multipart/form-data" action="_URL_" > method="POST"> > <input type="hidden" name="MAX_FILE_SIZE" > value="1000">Send this > file: <input name="userfile" type="file"> <input > type="submit" > value="Send File"> > </form> > > My problem is that i don´t know how to programe the php program that > upload the file. I do a lot of examples, but not work. > > Can someone give me help. > > > Thanks. > > > Best regards, Diego > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#53632) next »