faqts : Computers : Programming : Languages : PHP : Common Problems : File Uploading

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

22 of 40 people (55%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How do I upload a file with a PHP script while SafeMode is turned on?

Sep 8th, 2002 03:55
Reza A Tabibazar, Steve Holmquist,


Just use move_uploaded_file() instead of copy()
working example;
-----------------------------
<HTML>
<TITLE>
File upload
</title>
<body>
<B>File upload</b>
<form enctype="multipart/form-data" action="<?PHP echo $PHP_SELF ?>" 
method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
Send this file: 
 <input name="userfile" type="file">
<input type="submit" name="submit" value="Send File">
</form>
</body>
<?PHP
// copy to this directory
$dir="./uploads/";
// copy the file to the server
if (isset($submit)){
if (!is_uploaded_file ($userfile)){
   echo "<b>$userfile_name</b> couldn't be copied !!";
}
// check whether it has been uploaded
if (is_uploaded_file ($userfile)){
  move_uploaded_file($userfile,$dir.$userfile_name) ;}
   echo "<b>$userfile_name</b> copied succesfully !!";
}
?>
</html>