file upload script
| From: | Rodney Green | Date: | Sun, 08 Jun 2003 01:43:40 +0000 |
| Subject: | file upload script | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-150620@lists.php.net to get a copy of this message | ||
Hello. I'm attempting to upload a file using the script below and I'm not
having any success. The temp directory I'm using does exist and is
writeable. When I browse for the file then hit the send button it appears to
be working then displays the form again with no errors. I look for the file
on the server and it isn't there. Any advice on how to get this working?
Thanks!
Rod
---------------------------------------------------------------
<html>
<head>
<title>Listing 9.14 A file upload script</title>
</head>
<?php
$file_dir = "/home/corrdev/htdocs/php24/scrap/uploads";
$file_url = "http://corros.colo.hosteurope.com/dev/php24/scrap/uploads";
foreach( $HTTP_POST_FILES as $file_name => $file_array ) {
print "path: ".$file_array['tmp_name']."<br>\n";
print "name: ".$file_array['name']."<br>\n";
print "type: ".$file_array['type']."<br>\n";
print "size: ".$file_array['size']."<br>\n";
if ( is_uploaded_file( $file_array['tmp_name'] )
&& $file_array['type'] == "image/gif" ) {
move_uploaded_file( $file_array['tmp_name'], "$file_dir/$file_name")
or die ("Couldn't copy");
print "<img src=\"$file_url/$file_name\"><p>\n\n";
}
}
?>
<body>
<form enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="51200">
<input type="file" name="fupload"><br>
<input type="submit" value="Send file!">
</form>
</body>
</html>