Uploading a file
Posted: Wed Aug 17, 2011 11:06 am
Hello All,
I am new to php and am trying to write a function to upload a file to my server. The function works great with images but fails when I try to upload a file type with no mime type (binary file). How do I fix this? In the code below, the binary file I am trying to upload has the .lst extension and is binary data.
My Php code is as follow:
When I upload a .png file, everthing goes well and print_r($_FILES); prints the correct info. However, when uploading a .lst file I get this error:
[text]Notice: Undefined index: file in upload_file.php on line 7
Array
(
)[/text]
I am new to php and am trying to write a function to upload a file to my server. The function works great with images but fails when I try to upload a file type with no mime type (binary file). How do I fix this? In the code below, the binary file I am trying to upload has the .lst extension and is binary data.
My Php code is as follow:
Code: Select all
<?php
include('AnalyseListMode.html');
$allowedExtensions = array("lst","png");
$target = "upload/";
echo $_FILES['file'];
print "<pre>";
print_r($_FILES);
print "</pre>";
if (!in_array(end(explode(".", strtolower($_FILES["file"]['name']))), $allowedExtensions)){
die('invalid extenstion');
}
echo '<br>';
echo basename( $_FILES['file']['name']);
$target = $target . basename( $_FILES['file']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['file']['tmp_name'], $target))
{
//echo "The file ". basename( $_FILES['file']['name']). " has been file";
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
//echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
//echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
else {
echo "Sorry, there was a problem uploading your file.";
}
?>[text]Notice: Undefined index: file in upload_file.php on line 7
Array
(
)[/text]