GarryOne Posted May 16, 2011 Report Posted May 16, 2011 (edited) nu functioneaza codul si vreau ca voi sa-mi spuneti unde e greseala, si ce sa fac ca sa repar codul sa functioneze.imi apare Parse error: syntax error, unexpected T_ELSE in /home/a9540258/public_html/www/upload.php on line 31.ideea era, sa fac un script care sa accepta doar extensiile .txt .xml. .html .htm , daca fisierul uploadat nu respecta aceasta conditie sa se afeseze die($file['name'].' is an invalid file type!<br/>'); , daca uploadul se efectueaza cu succes sa-mi arata continutul fisierul uploadat.upload.php<?phpinclude('utilities.php');$folder="data/images/";$foto=$folder.'file.txt';if ($_FILES['foto']['tmp_name']) { move_uploaded_file($_FILES['foto']['tmp_name'], "$foto"); $allowedExtensions = array("txt","htm","html","xml"); if ($file['tmp_name'] > '') { if (!in_array(end(explode(".", strtolower($file['name']))), $allowedExtensions)) { die($file['name'].' is an invalid file type!<br/>'); } } } if ( $type!= "txt") { $_SESSION['error']='<p>Eroare. Incercati din nou.</p>'; unlink($foto); redir('index.php'); } else { redir('index.php?rs=ok'); }else { redir('index.php'); }?>home.php <?php if(isset($_GET['rs'])) { $result=$_GET['rs']; } if($result=='ok') { echo 'data/images/file.txt'; } else { if(!empty($_SESSION['error'])) { echo $_SESSION['error']; $_SESSION['error']=""; } echo '<form action="upload.php" method="post" enctype="multipart/form-data" name="upload" > <input type="file" name="foto" /> <br /> <input type="submit" value="Uploadeaza" /> </form>'; } ?> Edited May 16, 2011 by GarryOne Quote
nedo Posted May 16, 2011 Report Posted May 16, 2011 ai 2 else-uri aiureaelse { redir('index.php?rs=ok'); } si else { redir('index.php'); }in plus ai o "}" aiurea pusa, incearca cu asta<?phpinclude('utilities.php');$folder="data/images/";$foto=$folder.'file.txt';if ($_FILES['foto']['tmp_name']) { move_uploaded_file($_FILES['foto']['tmp_name'], "$foto"); $allowedExtensions = array("txt","htm","html","xml"); if ($file['tmp_name'] > '') { if (!in_array(end(explode(".", strtolower($file['name']))), $allowedExtensions)) { die($file['name'].' is an invalid file type!<br/>'); } } //mutam "}" de aici mai jos if ( $type!= "txt") { $_SESSION['error']='<p>Eroare. Incercati din nou.</p>'; unlink($foto); redir('index.php'); } else { redir('index.php?rs=ok'); } } // aicielse { redir('index.php'); }?> Quote
GarryOne Posted May 16, 2011 Author Report Posted May 16, 2011 mc, ceva ceva se misca, cand uploadez un fisier cu extensia in afara de acele propuse, imi da eroare, cum ar trebui, insa problema este ca cand uploadez un fisier text, nu se uploadeaza cu succes si nu-mi arata continutul insa imi da eroare la fel ca si cu ma as uploada alt tip de extensie.m-am uitat in folderul respectiv unde trebuia sa se uploadeze fisierul si nu este nimic Quote
turnback Posted May 16, 2011 Report Posted May 16, 2011 joaca-te cu catch si throw... PHP Exception Handling Quote