caricamento file in sottocartella nome utente

  • Creatore Discussione Creatore Discussione Imperor
  • Data di inizio Data di inizio

Imperor

Utente Attivo
25 Nov 2010
102
2
18
Roma
www.fcfclean.it
Buongiorno sto provato a caricare un doc pdf in ogni sottocartella ma mi da errore riga 83 la sottocartella si tova in documenti/cartella nome utente non riesco a capire perchè il file lo mette solo in documenti/ e no nella sotto cartella selezionata posto il codice
Codice:
 <?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
                    $subdir = 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($subdir as $subdir): ?>
                        <option value="<?= htmlspecialchars($subdir) ?>"><?= htmlspecialchars(basename($subdir)) ?></option>
                    <?php endforeach ?>
                      </select>
                     <input type="file" name="file" id="file">
                     <input type="submit" value="Upload File" name="submit">
                    </form>
 
Ultima modifica:
come ?
giusto per aiutare chi dovesse leggere questa richiesta in futuro
come ?
giusto per aiutare chi dovesse leggere questa richiesta in futuro
ciao ti posto il code completo
Codice:
 <?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 . "/";
                        $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 "Il file ". basename( $_FILES["file"]["name"]). " caricato con successo nella cartella di " . $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>
 

Discussioni simili