vishwas-027 / Test

1 stars 0 forks source link

Test #1

Open vishwas-027 opened 1 month ago

vishwas-027 commented 1 month ago

<?php

class FileUploadController { public function uploadCsvFile() { if ($_SERVER['REQUEST_METHOD'] === 'POST') { $targetDir = DIR . "/uploads/"; if (!file_exists($targetDir)) { mkdir($targetDir, 0777, true); }

        $targetFile = $targetDir . basename($_FILES["file"]["name"]);
        $fileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));

        if ($fileType != "csv") {
            echo "Only CSV files are allowed.";
            return;
        }

        if (move_uploaded_file($_FILES["file"]["tmp_name"], $targetFile)) {
            echo "The file " . htmlspecialchars(basename($_FILES["file"]["name"])) . " has been uploaded.";
        } else {
            echo "Sorry, there was an error uploading your file.";
        }
    }
}

}

class FileBrowserController { public function getCsvFiles() { $dir = DIR . "/uploads/"; $files = [];

    if (file_exists($dir)) {
        $files = array_diff(scandir($dir), array('.', '..'));
    }

    header('Content-Type: application/json');
    echo json_encode($files);
}

}

vishwas-027 commented 1 month ago

<?php

class FileUploadController { public function uploadCsvFile() { if ($_SERVER['REQUEST_METHOD'] === 'POST') { $targetDir = DIR . "/uploads/"; if (!file_exists($targetDir)) { mkdir($targetDir, 0777, true); }

        $targetFile = $targetDir . basename($_FILES["file"]["name"]);
        $fileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));

        if ($fileType != "csv") {
            echo "Only CSV files are allowed.";
            return;
        }

        if (move_uploaded_file($_FILES["file"]["tmp_name"], $targetFile)) {
            echo "The file " . htmlspecialchars(basename($_FILES["file"]["name"])) . " has been uploaded.";
        } else {
            echo "Sorry, there was an error uploading your file.";
        }
    }
}

}

class FileBrowserController { public function getCsvFiles() { $dir = DIR . "/uploads/"; $files = [];

    if (file_exists($dir)) {
        $files = array_diff(scandir($dir), array('.', '..'));
    }

    header('Content-Type: application/json');
    echo json_encode($files);
}

}

vishwas-027 commented 1 month ago

<?php

class FileUploadController { public function uploadCsvFile() { if ($_SERVER['REQUEST_METHOD'] === 'POST') { $targetDir = DIR . "/uploads/"; if (!file_exists($targetDir)) { mkdir($targetDir, 0777, true); }

        $targetFile = $targetDir . basename($_FILES["file"]["name"]);
        $fileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));

        if ($fileType != "csv") {
            echo "Only CSV files are allowed.";
            return;
        }

        if (move_uploaded_file($_FILES["file"]["tmp_name"], $targetFile)) {
            echo "The file " . htmlspecialchars(basename($_FILES["file"]["name"])) . " has been uploaded.";
        } else {
            echo "Sorry, there was an error uploading your file.";
        }
    }
}

}

class FileBrowserController { public function getCsvFiles() { $dir = DIR . "/uploads/"; $files = [];

    if (file_exists($dir)) {
        $files = array_diff(scandir($dir), array('.', '..'));
    }

    header('Content-Type: application/json');
    echo json_encode($files);
}

}

vishwas-027 commented 1 month ago

Hi

vishwas-027 commented 1 month ago

<?php

class FileUploadController { public function uploadCsvFile() { if ($_SERVER['REQUEST_METHOD'] === 'POST') { $targetDir = DIR . "/uploads/"; if (!file_exists($targetDir)) { mkdir($targetDir, 0777, true); }

        $targetFile = $targetDir . basename($_FILES["file"]["name"]);
        $fileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));

        if ($fileType != "csv") {
            echo "Only CSV files are allowed.";
            return;
        }

        if (move_uploaded_file($_FILES["file"]["tmp_name"], $targetFile)) {
            echo "The file " . htmlspecialchars(basename($_FILES["file"]["name"])) . " has been uploaded.";
        } else {
            echo "Sorry, there was an error uploading your file.";
        }
    }
}

}

class FileBrowserController { public function getCsvFiles() { $dir = DIR . "/uploads/"; $files = [];

    if (file_exists($dir)) {
        $files = array_diff(scandir($dir), array('.', '..'));
    }

    header('Content-Type: application/json');
    echo json_encode($files);
}

}``