rewrite v1.0

This commit is contained in:
Pontoporeia
2023-05-02 20:17:58 +02:00
parent 763ad7d722
commit 4a1e4b696e
9 changed files with 301 additions and 25 deletions

View File

@@ -5,6 +5,9 @@ ini_set('display_errors', 0);
ini_set('log_errors', 1);
ini_set('error_log', 'error.log');
// Log the content of the $_FILES array
error_log("FILES array: " . print_r($_FILES, true));
require_once 'vendor/autoload.php';
use Symfony\Component\Yaml\Yaml;
use Behat\Transliterator\Transliterator;
@@ -51,30 +54,43 @@ $maxFileSize = 5 * 1024 * 1024; // 5 MB
// Process uploaded files
if (is_array($files["name"])) {
for ($i = 0; $i < count($files["name"]); $i++) {
// Log the file being processed
error_log("Processing file: " . $files["name"][$i]);
// Check for file upload errors
if ($files["error"][$i] !== UPLOAD_ERR_OK) {
error_log("File upload error: " . $files["name"][$i]);
continue;
}
// Check MIME type and file extension
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mimeType = $finfo->file($files["tmp_name"][$i]);
$fileExtension = pathinfo($files["name"][$i], PATHINFO_EXTENSION);
if (!in_array($mimeType, $allowedMimeTypes) || !in_array($fileExtension, $allowedExtensions)) {
echo "Invalid file type or extension: " . $files["name"][$i] . "<br>";
error_log("Invalid file type or extension: " . $files["name"][$i]);
continue;
}
// Check file size
if ($files["size"][$i] > $maxFileSize) {
echo "File is too large: " . $files["name"][$i] . "<br>";
error_log("File is too large: " . $files["name"][$i]);
continue;
}
// Move and set permissions for the uploaded file
$targetFile = $targetDir . basename($files["name"][$i]);
move_uploaded_file($files["tmp_name"][$i], $targetFile);
chmod($targetFile, 0644);
$uploadedFiles[] = $targetFile;
if (move_uploaded_file($files["tmp_name"][$i], $targetFile)) {
// Log successful file move
error_log("File successfully moved: " . $targetFile);
chmod($targetFile, 0644);
$uploadedFiles[] = $targetFile;
} else {
error_log("Failed to move uploaded file: " . $files["name"][$i]);
}
}
}
// Prepare form data for YAML
$formData = [
'auteurice' => $auteurice,
@@ -100,3 +116,4 @@ file_put_contents($yamlFilePath, $yamlData);
// Redirect to the thank you page
header('Location: thanks.php?file=' . urlencode($yamlFilePath));
?>