<?
/ ---| upload.php |------------------- +
| By Mike Girouard (kingmike@p0w3r.com) |
| Copyright (c) 2002 ExoticDogs.com |
| ------------------------------------- |
| Uploads a file to a directory. This |
| script can be easily modified to send |
| ANY type of file. This script is |
| suitable for uploading one file at a |
| time. |
+ ------------------------------------ /
// Set some important variables to be used later on
// throughout this script.
$max_s = 66560; // Maximum file size in bytes.
$max_w = 650; // Maximum image width in pixels.
$max_h = 800; // Maximum image height in pixels.
$fpath = '/home/web/exoticdogs.com/docs/customer_images';
// Create the array of allowed image types. When
// images are uploaded we will check the image types
// against this array.
$allowed = array(
"image/gif",
"image/x-png",
"image/pjpeg",
"image/jpeg"
);
// Create the array to store logged information,
// directions, and error info that will be displayed
// when uploading images.
$info = array();
?>
<pre>
<? print_r($_FILES) ?>
</pre>
<?
if(sizeof($POST) > 0) {
for($c = 0; $c < sizeof($FILES['name']); $c++) {
if((isset($FILES['image']['tmp_name'][$c])) && ($FILES['image']['tmp_name'][$c] != 'none')) {
$fdim = getimagesize($_FILES['image']['tmp_name'][$c]);
// Inspect the image to make sure that it
// suitable on the server.
if(!in_array($_FILES['image']['type'][$c],$allowed)) array_push($info,'File type is not allowed ('.$_FILES['image']['type'][$c].').');
if($_FILES['image']['size'][$c] > $max_s) array_push($info,'File size is too large ('.$_FILES['image']['size'][$c].' bytes).');
if($fdim[0] > $max_w) array_push($info,'Image width is too wide ('.$fdim[0].' pixels).');
if($fdim[1] > $max_h) array_push($info,'Image height is too tall ('.$fdim[1].' pixels).');
if(sizeof($info) == 0) {
if(move_uploaded_file($_FILES['image']['tmp_name'][$c],$fpath.'/'.$_FILES['image']['name'][$c])) {
array_push($info,$_FILES['image']['name'][$c].' was uploaded sucessfully');
}
else array_push($info,"Upload failed. Unknown error.");
}
else array_push($info,$_FILES['image']['name'][$c].' was refused for upload. See above errors.');
}
else array_push($info,'You didn\'t choose a file to upload');
}
}
else {
array_push($info,'Choose a file for uploading by clicking the "Browse'.
'" button below. When you are done click the "'.
'Upload >>" button.');
}
?>
<head>
<title> File Upload </title>
</head>
<body bgcolor="#EAEAEA">
<form method="post" action="<?=$_SERVER['PHP_SELF']?>" enctype="multipart/form-data">
<p>
<?
// Print out any information, directons or error
// messages that have been collected.
for($i = 0; $i < sizeof($info); $i++) {
echo $info[$i]."<br>\n";
}
?>
<hr>
<input type="file" name="image[]"><br>
<input type="file" name="image[]"><br>
<input type="file" name="image[]"><br>
<input type="file" name="image[]"><br>
<input type="file" name="image[]"><br>
<input type="file" name="image[]"><br>
<input type="submit" name="submit" value="Upload >>">
</p>
</form>
</body>