0

I have a weird problem, I have a php upload code that I have implemented long ago, today I try to reuse it but it didn't work, the surprise was big when I started my Windows on VirtualBox and the exact same file that I was unable to upload from linux was uploaded for windows. I mean, the only thing that changes is the OS of client machine. Any way, I think is related to the file type restriction, because if I take out these restrictions I can upload the file from my ubuntu....

Codes are next: form.php file:

<form action="upload.php" method="post" enctype="multipart/form-data">
<input name="file" type="file" size="50" /><br>
<p><input name="upload" type="submit" value="upload" />
<input name="action" type="hidden" value="upload" /></p></form>

upload.php file:

<?php
$status = "";
if ($_POST["action"] == "upload") {
// data from file
$size = $_FILES["file"]['size'];
$type = $_FILES["file"]['type'];
$file = $_FILES["file"]['name'];
$pos = strpos($file, "_timetable.csv");

if ($file != "") {
if ($type == "text/csv" || $type == "application/vnd.ms-excel") {
if ($pos == false) {
$status = "Error: only files with extension <b>_timetable.csv</b> are allowed
<p><form action=\"form.php\"><input type=\"submit\" value=\"&nbsp; Select a different file &nbsp;\"></p>";
}else {
$destination = "filess/".$fitxer;
if (copy($_FILES['file']['tmp_name'],$destination)) {
$status = "<p>Uploaded: ".$file."</p>
}
 else {
$status = "Error when uploading file<p><form action=\"form.php\"><input type=\"submit\"
value=\"&nbsp; Try again &nbsp;\"></p>";
}
}} else {
$status = "Error: only files with extension <b>_timetable.csv</b> are allowed
<p><form action=\"form.php\"><input type=\"submit\" value=\"&nbsp; Select a different file &nbsp;\"></p>";
}
} else {
$status = "Error when uploading file<p><form action=\"form.php\"><input type=\"submit\"
value=\"&nbsp; Try again &nbsp;\"></p>";
}
}
echo $status;
?>
Andrés Chandía
  • 999
  • 1
  • 16
  • 32

0 Answers0