• User Attivo

    Upload foto multiple errore nel codice

    Salve a tutti,
    posto qui un'altra questione
    Ho prelevato da un sito (free) il codice per caricare le foto e memorizzare il nome nel database e salvare nella cartella specificata

    Tutto a posto, lo adattato al mio database e funziona benissimo, questo pero' per caricare una foto (per gli attori),

    ho pensato di duplicare un altro per i film e caricare la cover frontale e posteriore, i campi sono cover_front e **cover_back
    **naturalmente ho dovuto modificare il codice per accettare il caricamento di 2 foto (l'originale e strutturato solo per una)

    per qualche errore che non riesco ad individuare fa l'upload della solo foto posteriore (cover_back)
    quella frontale non riesco a caricarla

    image

    ecco il codice php

    index.php

    [PHP]<?php include('header.php'); ?>
    <body>

    <div class="row-fluid">
        <div class="span12">
    
    
         
    
            <div class="container">
    

    <?php include ('modal_add.php'); ?>

                        <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
                            <div class="alert alert-info">
                                <button type="button" class="close" data-dismiss="alert">&times;</button>
                                <strong><i class="icon-user icon-large"></i>&nbsp;Data Table</strong>
                            </div>
                            <thead>
                                <tr>
                                    <th style="text-align:center;">Cover Front</th>
                                    <th style="text-align:center;">Cover Back</th>
                                    <th style="text-align:center;">Movie Title</th>
                                    <th style="text-align:center;">Year</th>
                                    <th style="text-align:center;">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php
                                require_once('db.php');
                                $result = $conn->prepare("SELECT * FROM film ORDER BY film_id ASC");
                                $result->execute();
                                for($i=0; $row = $result->fetch(); $i++){
                                $id=$row['film_id'];
                            ?>
                                <tr>
                                <td style="text-align:center; margin-top:10px; word-break:break-all; width:450px; line-height:100px;">
                                    <?php if($row['cover_front'] != ""): ?>
                                    <img src="uploads/<?php echo $row['cover_front']; ?>" width="100px" height="100px" style="border:1px solid #333333;">
                                    <?php else: ?>
                                    <img src="http://www.giorgiotave.it/forum/images/default.png" width="100px" height="100px" style="border:1px solid;">
                                    <?php endif; ?>
                                </td>
                                <td style="text-align:center; margin-top:10px; word-break:break-all; width:450px; line-height:100px;">
                                    <?php if($row['cover_back'] != ""): ?>
                                    <img src="uploads/<?php echo $row['cover_back']; ?>" width="100px" height="100px" style="border:1px solid;">
                                    <?php else: ?>
                                    <img src="http://www.giorgiotave.it/forum/images/default.png" width="100px" height="100px" style="border:1px solid;">
                                    <?php endif; ?>
                                </td>
                                <td style="text-align:center; word-break:break-all; width:300px;"> <?php echo $row ['movie_title']; ?></td>
                                <td style="text-align:center; word-break:break-all; width:200px;"> <?php echo $row ['year']; ?></td>                                
                                <td style="text-align:center; width:350px;">
                                     <a href="#updte_img1<?php echo $id;?>"  data-toggle="modal"  class="btn btn-warning" >Update Cover Front</a>
                                     <a href="#updte_img2<?php echo $id;?>"  data-toggle="modal"  class="btn btn-warning" >Update Cover Back</a>
                                     <a href="#delete1<?php echo $id;?>"  data-toggle="modal"  class="btn btn-danger" >Delete Cover Front</a>
                                     <a href="#delete2<?php echo $id;?>"  data-toggle="modal"  class="btn btn-danger" >Delete Cover Back</a>
                                </td>
                                </tr>
                                        <!-- Modal -->
                            <div id="delete1<?php  echo $id;?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                            <div class="modal-header">
                            <h3 id="myModalLabel">Delete</h3>
                            </div>
                            <div class="modal-body">
                            <div class="alert alert-danger">
                            <?php if($row['cover_front'] != ""): ?>
                            <img src="uploads/<?php echo $row['cover_front']; ?>" width="100px" height="100px" style="border:1px solid;">
                            <?php else: ?>
                            <img src="http://www.giorgiotave.it/forum/images/default.png" width="100px" height="100px" style="border:1px solid; margin-left:15px;">
                            <?php endif; ?>
                            <b style="color:blue; margin-left:25px; font-size:30px;"><?php echo $row['movie_title']; ?></b>
                            <br />
                            <p style="font-size: larger; text-align: center;">Are you Sure you want to Delete?</p>
                            </div>
                            <hr>
                            <div class="modal-footer">
                            <button class="btn btn-inverse" data-dismiss="modal" aria-hidden="true">No</button>
                            <a href="delete.php<?php echo '?film_id='.$id; ?>" class="btn btn-danger">Yes</a>
                            </div>
                            </div>
                            </div>
                            <!-- Modal -->
                            <div id="delete2<?php  echo $id;?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                            <div class="modal-header">
                            <h3 id="myModalLabel">Delete</h3>
                            </div>
                            <div class="modal-body">
                            <div class="alert alert-danger">
                            <?php if($row['cover_front'] != ""): ?>
                            <img src="uploads/<?php echo $row['cover_front']; ?>" width="100px" height="100px" style="border:1px solid;">
                            <?php else: ?>
                            <img src="http://www.giorgiotave.it/forum/images/default.png" width="100px" height="100px" style="border:1px solid; margin-left:15px;">
                            <?php endif; ?>
                            <b style="color:blue; margin-left:25px; font-size:30px;"><?php echo $row['movie_title']; ?></b>
                            <br />
                            <p style="font-size: larger; text-align: center;">Are you Sure you want to Delete?</p>
                            </div>
                            <hr>
                            <div class="modal-footer">
                            <button class="btn btn-inverse" data-dismiss="modal" aria-hidden="true">No</button>
                            <a href="delete.php<?php echo '?film_id='.$id; ?>" class="btn btn-danger">Yes</a>
                            </div>
                            </div>
                            </div>
                                        <!-- Modal Update Image -->
                            <div id="updte_img1<?php  echo $id;?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                            <div class="modal-header">
                            <h3 id="myModalLabel">Update1</h3>
                            </div>
                            <div class="modal-body">
                            <div class="alert alert-danger">
                            <?php if($row['cover_front'] != ""): ?>
                            <img src="uploads/<?php echo $row['cover_front']; ?>" width="100px" height="100px" style="border:1px solid; margin-left: 30px;">
                            <?php else: ?>
                            <img src="http://www.giorgiotave.it/forum/images/default.png" width="100px" height="100px" style="border:1px solid; margin-left: 30px;">
                            <?php endif; ?>
                            <form action="edit_PDO.php<?php echo '?film_id='.$id; ?>" method="post" enctype="multipart/form-data">
                            <div style="color:blue; margin-left:150px; font-size:30px;">
                                <input type="file" name="image" style="margin-top:-115px;">
                            </div>
                            </div>
                            <hr>
                            <div class="modal-footer">
                            <button class="btn btn-inverse" data-dismiss="modal" aria-hidden="true">No</button>
                            <button type="submit" name="submit" class="btn btn-danger">Yes</button>
                            </form>
                            </div>
                            </div>
                            </div>
                            <!-- Modal Update Image -->
                            <div id="updte_img2<?php  echo $id;?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                            <div class="modal-header">
                            <h3 id="myModalLabel">Update2</h3>
                            </div>
                            <div class="modal-body">
                            <div class="alert alert-danger">
                            <?php if($row['cover_back'] != ""): ?>
                            <img src="uploads/<?php echo $row['cover_back']; ?>" width="100px" height="100px" style="border:1px solid; margin-left: 30px;">
                            <?php else: ?>
                            <img src="http://www.giorgiotave.it/forum/images/default.png" width="100px" height="100px" style="border:1px solid; margin-left: 30px;">
                            <?php endif; ?>
                            <form action="edit_PDO.php<?php echo '?film_id='.$id; ?>" method="post" enctype="multipart/form-data">
                            <div style="color:blue; margin-left:150px; font-size:30px;">
                                <input type="file" name="image" style="margin-top:-115px;">
                            </div>
                            </div>
                            <hr>
                            <div class="modal-footer">
                            <button class="btn btn-inverse" data-dismiss="modal" aria-hidden="true">No</button>
                            <button type="submit" name="submit" class="btn btn-danger">Yes</button>
                            </form>
                            </div>
                            </div>
                            </div>
                                <?php } ?>
                            </tbody>
                        </table>
    
    
          
        </div>
        </div>
        </div>
    </div>
    

    </body>
    </html>

    [/PHP]

    upload.php

    [PHP]<?php

    require_once ('db.php');

    if (isset($_POST['Submit'])) {
    // echo "";
    // }else{
    // $file=$_FILES['image']['tmp_name'];
    // $image = $_FILES["image"] ["name"];
    // $image_name= addslashes($_FILES['image']['name']);
    // $size = $_FILES["image"] ;
    // $error = $_FILES["image"] ["error"];
    //
    // if ($error > 0){
    // die("Error uploading file! Code $error.");
    // }else{
    // if($size > 10000000) //conditions for the file
    // {
    // die("Format is not allowed or file size is too big!");
    // }
    //
    // else
    // {
    move_uploaded_file($_FILES["image"]["tmp_name"],"uploads/" . $_FILES["image"]["name"]);
    $location1=$_FILES["image"]["name"];
    $fname1=$_POST['nome'];
    $location2=$_FILES["image"]["name"];
    $fname2=$_POST['nome'];

    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "INSERT INTO film (nome, cover_front)
    VALUES ('$fname1', '$location1')";
    $sql = "INSERT INTO film (nome, cover_back)
    VALUES ('$fname2', '$location2')";

    $conn->exec($sql);
    echo "<script>alert('Successfully Added!!!'); window.location='index.php'</script>";
    // }
    }
    // }
    ?>[/PHP]

    editPDO.php

    [PHP]<?php

    require_once ('db.php');

    $get_id=$_REQUEST['film_id'];

    move_uploaded_file($_FILES["image"]["tmp_name"],"uploads/" . $_FILES["image"]["name"]);
    $location1=$_FILES["image"]["name"];
    $location2=$_FILES["image"]["name"];

    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "UPDATE film SET cover_front ='$location1' WHERE film_id = '$get_id' ";
    $sql = "UPDATE film SET cover_back ='$location2' WHERE film_id = '$get_id' ";

    $conn->exec($sql);
    echo "<script>alert('Successfully Updated!!!'); window.location='index.php'</script>";
    ?>[/PHP]

    add.php

    [PHP]<?php
    require_once('db.php');

    $fname= $_POST['movie_title'];
    $paka= $_POST['year'];

    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "INSERT INTO film (movie_title, year)
    VALUES ('$fname', '$paka')";

    $conn->exec($sql);
    echo "<script>alert('Account successfully added!'); window.location='index.php'</script>";
    ?>[/PHP]

    **delete.php

    **questo non capisco come devo impostarlo per scegliere di cancellare la cover_front o cover_back dal database, la tabella e film e i campi sono cover_front e cover_back

    [PHP]<?php
    require_once('db.php');

    $get_id=$_GET['tbl_image_id'];

    // sql to delete a record
    $sql = "Delete from tbl_image where tbl_image_id = '$get_id'";

    // use exec() because no results are returned
    $conn->exec($sql);
    header('location:index.php');
    ?>[/PHP]

    ci sono altri file, ma e' codice html e altro per gestire Datatables

    qualcuno riesce a capire dove ho sbagliato? 😞


  • User Attivo

    Soluzione per questo? :bho: