I've managed to make a little upload script for uploading files to a shared dir on my server where me and my co-workers share media files. Is there anyone who cares to take a look at it and perhaps make some suggestions to things that may be done in a better way?
if($upload){//submit button in form
if($fil= addslashes(fread(fopen($data, "rb"), filesize($data)))){
write_file($data, $fil);//call to function write_file
header("Location: tradefiles.php?user=".$_SESSION['user']."");
}else echo "shit";
}
function write_file($data, $fil){
$raw = fread(fopen($data, "r"), filesize($data));
$fs = filesize($data);
$file_dir = ".";
$file_url = "http://xx.xx.xx";
echo "This file was uploaded:<br>";
foreach( $_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";
move_uploaded_file( $file_array['tmp_name'], $file_dir.'/'.$file_array['name'] )
or die ("Couldn't Copy");
}
if (!$handle = fopen($file_array['name'], 'w+')) {
print "Cannot open file (".$file_array['name'].")";
exit;
}
if (!fwrite($handle, $raw)) {
print "Cannot write to file (".$file_array['name'].")";
exit;
}
fclose($handle);
}
This script is used on a MS WIN2003 server with IIS and PHP 4.3xx