Ciao a tutti,
ho una funzione scritta in php che viene richiamata (a quanto pare) anche quando non dovrebbe essere richiamata.
vi incollo tutta la pagina php così avete una visione completa
codice:<?phpsession_start(); /* FUNCTION COMPRESS IMAGE */ function compress_image($source_url,$destination_url,$quality) { $info = getimagesize($source_url); if($info['mime'] == 'image/jpeg') { $image = imagecreatefromjpeg($source_url); } elseif($info['mime'] == 'image/png') { $image = imagecreatefrompng($source_url); } imagejpeg($image,$destination_url,$quality); return $destination_url; } /* IMAGE RESIZE LIBRARY */ include_once 'ImageResize.php'; use \Eventviva\ImageResize; include_once 'config.php'; // PRENDO INFO NEWS if(isset($_GET['news'])) { $sel_news = $db->prepare("SELECT * FROM mbe_news WHERE id=:id"); $sel_news->execute(array(':id'=>$_GET['news'])); $res_news = $sel_news->fetch(); $titolo = $res_news[2]; $descrizione = $res_news[3]; $sorgente = $res_news[4]; // MODIFICA GALLERY if(isset($_POST['submitModNews']) and $_SERVER['REQUEST_METHOD'] == "POST") { $mod_news = $db->prepare("UPDATE mbe_news SET titolo=:titolo, descrizione=:descrizione WHERE id=:id"); $mod_news->execute(array(':titolo'=>$_POST['inputModTitle'],':descrizione'=>$_POST['inputModTesto'],':id'=>$_GET['news'])); // aggiungi immagini a gallery esistente $cartella_news = "img/news/".$_GET['news']; if(!empty($_FILES["mod_gallery_news"])) { $num_files = count($_FILES["mod_gallery_news"]["tmp_name"]); for($i=0;$i<$num_files;$i++) { compress_image($_FILES["mod_gallery_news"]["tmp_name"][$i],$cartella_news."/".$_FILES["mod_gallery_news"]["name"][$i],90); } $resize_files = glob($cartella_news."/*.*"); for($i=0;$i<count($resize_files);$i++) { $image = $resize_files[$i]; $supported_file = array('jpg','jpeg','png','JPG','PNG','JPEG'); $ext = strtolower(pathinfo($image, PATHINFO_EXTENSION)); if(in_array($ext, $supported_file)) { $resize = new ImageResize($image); $resize->resizeToHeight(500); $resize->save($image); } else { continue; } } } header("Location:list_news_admin.php"); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>MBE - Admin</title> <!-- FAVICON --> <link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon"> <link rel="icon" href="img/favicon.ico" type="image/x-icon"> <!-- /FAVICON --> <link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css"> <link href="css/pingendo-bootstrap.css" rel="stylesheet" type="text/css"> <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" rel="stylesheet"> <link href="css/bootstrap-toggle.min.css" rel="stylesheet"> <!-- Custom styles for this template --> <link href="css/style.css" rel="stylesheet"> <!-- Just for debugging purposes. Don't actually copy this line! --> <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]--> <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> <![endif]--> </head> <body> <?php if(!isset($_SESSION['admin'])) { ?> <div class="section dark"> <div class="container"> <div class="row"> <div class="col-md-12 col-sm-12 col-xs-12 text-center"> <h1 class="title">Pannello di controllo <i class="fa fa-cog fa-spin"></i></h1> </div> <div class="col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-1 col-xs-12 text-center"> <form class="margined-top" method="POST" action="login.php"> <div class="form-group col-md-12 col-sm-12 col-xs-12"> <label class="label-light" for="inputAdmin">Username</label> <input type="text" class="form-control" id="inputAdmin" name="inputAdmin"> </div> <div class="form-group col-md-12 col-sm-12 col-xs-12"> <label class="label-light" for="inputPassword">Password</label> <input type="password" class="form-control" id="inputPassword" name="inputPassword"> </div> <div class="form-group col-md-12 col-sm-12 col-xs-12 text-center"> <a href="index.php" class="btn btn-lg btn-primary">Torna al sito</a> <button type="submit" class="btn btn-lg btn-success" name="submitAdmin">Accedi</button> </div> </form> </div> </div> </div> </div> <?php } else { ?> <div class="section dark"> <div class="container"> <div class="row"> <div class="col-md-12 col-sm-12 col-xs-12 text-center"> <h1 class="title">Benvenuto Amministratore</h1> <h2 class="subtitle">Modifica News</h2> </div> <div class="col-md-12 col-sm-12 col-xs-12 text-center margined-top"> <div class="col-md-4 col-sm-4 col-xs-12"> <a href="index.php" class="btn btn-lg btn-block btn-primary"><i class="fa fa-home"></i> Home</a> </div> <div class="col-md-4 col-sm-4 col-xs-12"> <a href="admin.php" class="btn btn-lg btn-block btn-warning"><i class="fa fa-wrench"></i> Pannello</a> </div> <div class="col-md-4 col-sm-4 col-xs-12"> <a href="logout.php" class="btn btn-lg btn-block btn-danger"><i class="fa fa-times"></i> Esci</a> </div> </div> </div> </div> </div> <div class="section light"> <div class="container"> <div class="row"> <div class="col-md-12 col-sm-12 col-xs-12"> <a href="list_news_admin.php" class="btn btn-custom-black btn-lg"><i class="fa fa-chevron-left"></i> Indietro</a> </div> <form method="POST" action="modify-news.php?news=<?php echo $_GET['news'];?>" enctype="multipart/form-data"> <div class="col-md-6 col-sm-6 col-xs-12 text-left"> <?php $files = glob($sorgente."/*.*"); for($i=0;$i<count($files);$i++) { $image = $files[$i]; $supported_file = array('jpg','jpeg','png'); $ext = strtolower(pathinfo($image, PATHINFO_EXTENSION)); if(in_array($ext, $supported_file)) { ?> <div class="col-md-4 col-sm-4 col-xs-12 margined-top"> <img src="<?php echo $image;?>" alt="<?php echo $titolo;?>" style="width:100%;height:auto;"> <a href="delete-img.php?image=<?php echo $image;?>" class="btn btn-danger btn-block"><i class="fa fa-trash-o"></i> Elimina</a> </div> <?php } } ?> </div> <div class="col-md-6 col-sm-6 col-xs-12 text-center margined-top"> <div class="form-group"> <input type="text" name="inputModTitle" class="form-control" value="<?php echo $titolo;?>"> </div> <div class="form-group"> <textarea rows="10" name="inputModTesto" class="form-control"><?php echo $descrizione;?></textarea> </div> <div class="form-group"> <input type="file" name="mod_gallery_news[]" id="galleryImages" multiple="multiple" class="form-control" accept="image/*"> </div> </div> <div class="col-md-12 col-sm-12 col-xs-12 text-right margined-top"> <button type="reset" class="btn btn-lg btn-danger">Annulla <i class="fa fa-times"></i></button> <button type="submit" class="btn btn-lg btn-success" name="submitModNews">Modifica <i class="fa fa-pencil"></i></button> </div> </form> </div> </div> </div> <?php } ?> <script src="//cdn.ckeditor.com/4.5.6/basic/ckeditor.js"></script> <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> <script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> <script> CKEDITOR.replace('inputModTesto'); </script> </body> </html>
COSA SUCCEDE?
se io modifico ad esempio il titolo della news, e lascio vuoto il campo $_FILES quindi l'input file e premo il submit la pagina mi restituisce questi errori:
Notice: Undefined variable: info in /home/mbe026/public_html/modify-news.php on line 8
Notice: Undefined variable: info in /home/mbe026/public_html/modify-news.php on line 11
Notice: Undefined variable: image in /home/mbe026/public_html/modify-news.php on line 14
Warning: imagejpeg() expects parameter 1 to be resource, null given in /home/mbe026/public_html/modify-news.php on line 14
Warning: Cannot modify header information - headers already sent by (output started at /home/mbe026/public_html/modify-news.php:8) in /home/mbe026/public_html/modify-news.php on line 55

Rispondi quotando