- Home
- Categorie
- Coding e Sistemistica
- PHP
- php form seleziona sottocartella caricamento file pdf
-
php form seleziona sottocartella caricamento file pdf
buongiorno in rete ho trovato uno script dove seleziono la sottocartella e carico il file pdf o doc ho provato a modificarlo ma mi da sempre errore sicuramente sbaglio qualcosa la directory è documenti/cartella nome utente chiedo aiuto grazie
<?php // Check if the form was submitted if($_SERVER["REQUEST_METHOD"] == "POST"){ // Check if file was uploaded without errors if(isset($_FILES["file"]) && $_FILES["file"]["error"] == 0){ // Get the subdirectory from the select element $subdir = $_POST["subdir"]; // Set the destination path and filename $target_dir = "documenti/" . $subdir . "documenti/"; $target_file = $target_dir . basename($_FILES["file"]["name"]); // Move the uploaded file to the destination if(move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)){ echo "The file ". basename( $_FILES["file"]["name"]). " has been uploaded to " . $subdir . "."; } else{ echo "Sorry, there was an error uploading your file."; } } else{ echo "Error: " . $_FILES["file"]["error"]; } } ?> <h6>carica documento</h6> <?php $foldername = glob("documenti/*"); ?> <form action="admin.php" method="post" enctype="multipart/form-data"> <label for="select-cartella">Scegli la cartella di destinazione</label> <select name="subdir" id="subdir"> <?php foreach($foldername as $foldername): ?> <option value="<?= htmlspecialchars(basename($foldername)) ?>"><?= htmlspecialchars(basename($foldername)) ?></option> <?php endforeach ?> </select> <input type="file" name="file" id="file"> <input type="submit" value="Upload File" name="submit"> </form>
-
risolto