autonomous
05-04-2005, 02:55 AM
Was wondering if anyone could help me with the following script...
I'm trying to only let .xls files be uploaded..
I know my problem is around the line if (is_uploaded_file($file_array['tmp_name']!= $allowed_types)) But I'm not sure how to do what I'm trying to do... I just want to say if the file does not equal an allowed type then display the error ....
Any suggestions would greatly be appreciated.
Thanks,
sb.
<?php
$PHP_SELF;
$registered_types = array("application/msword" => ".doc", "application/vnd.ms-excel" => ".xls, .XLS", "application/octet-stream" => ".exe, .fla (etc)");
$allowed_types = array("application/vnd.ms-excel");
$file_dir = "/hsphere/local/home/mysite/downloads";
foreach($_FILES as $file_name => $file_array) {
if (is_uploaded_file($file_array['tmp_name']!= $allowed_types)) {
$error .= "\n<li>The file that you uploaded was of a type that is not allowed, you are only allowed to upload files of the type:\n<ul>";
while ($type = current($allowed_types)) {
$error .= "\n<li>" . $registered_types[$type] . " (" . $type . ")</li>";
next($allowed_types);
}
$error .= "\n</ul>";
}
if (is_uploaded_file($file_array['tmp_name'])) {
move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_array[name]") or die ("\nCurrently unable to connect, please check with your system administrator, check the path to and the permissions for the upload directory\n");
echo "<div class=\"Instructions\">".$file_array['name']."<br>has been uploaded to the Current Price List directory.</div>";
}
}
print "\n<form ENCTYPE=\"multipart/form-data\" action=\"" . $PHP_SELF . "\" method=\"post\">";
print "\n<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" . $my_max_file_size . "\">";
print "\n<INPUT TYPE=\"hidden\" name=\"task\" value=\"upload\">";
print "\n<P class=\"quote\"><b>Upload Price List</b><br>";
print "\n<br><INPUT NAME=\"the_file\" TYPE=\"file\" SIZE=\"25\" class=\"formSubmit\"><br>";
print "\n<input type=\"submit\" Value=\"Upload\" class=\"formSubmit\">";
print "\n</form>";
?>
I'm trying to only let .xls files be uploaded..
I know my problem is around the line if (is_uploaded_file($file_array['tmp_name']!= $allowed_types)) But I'm not sure how to do what I'm trying to do... I just want to say if the file does not equal an allowed type then display the error ....
Any suggestions would greatly be appreciated.
Thanks,
sb.
<?php
$PHP_SELF;
$registered_types = array("application/msword" => ".doc", "application/vnd.ms-excel" => ".xls, .XLS", "application/octet-stream" => ".exe, .fla (etc)");
$allowed_types = array("application/vnd.ms-excel");
$file_dir = "/hsphere/local/home/mysite/downloads";
foreach($_FILES as $file_name => $file_array) {
if (is_uploaded_file($file_array['tmp_name']!= $allowed_types)) {
$error .= "\n<li>The file that you uploaded was of a type that is not allowed, you are only allowed to upload files of the type:\n<ul>";
while ($type = current($allowed_types)) {
$error .= "\n<li>" . $registered_types[$type] . " (" . $type . ")</li>";
next($allowed_types);
}
$error .= "\n</ul>";
}
if (is_uploaded_file($file_array['tmp_name'])) {
move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_array[name]") or die ("\nCurrently unable to connect, please check with your system administrator, check the path to and the permissions for the upload directory\n");
echo "<div class=\"Instructions\">".$file_array['name']."<br>has been uploaded to the Current Price List directory.</div>";
}
}
print "\n<form ENCTYPE=\"multipart/form-data\" action=\"" . $PHP_SELF . "\" method=\"post\">";
print "\n<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" . $my_max_file_size . "\">";
print "\n<INPUT TYPE=\"hidden\" name=\"task\" value=\"upload\">";
print "\n<P class=\"quote\"><b>Upload Price List</b><br>";
print "\n<br><INPUT NAME=\"the_file\" TYPE=\"file\" SIZE=\"25\" class=\"formSubmit\"><br>";
print "\n<input type=\"submit\" Value=\"Upload\" class=\"formSubmit\">";
print "\n</form>";
?>
