Formularz - Gekku - 29-01-2012
Witam mam taki kod i chciałbym z niego usunąć dodawanie obrazka zeby bylo opcjonalne
Kod PHP: <?php /* Projekt: shitIMGv2 * Plik: dodaj.php * Data modyfikacji: 01-08-2011 * * Copyright (C) 2011 Paweł Klockiewicz & Wojciech Król * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ session_start(); //start sesji ob_start(); require_once('connect.php'); require_once('functions.php'); ?> <html> <head> <title><?php echo $ustawienia['tytul']; ?> - Dodaj obrazek</title> <?php include('tpl/head.php') ?> </head> <body> <div id="naglowek"> <!-- code by klocek & Quik --> <?php include('tpl/naglowek.php') ?> </div> <div id="menu"> <?php include('tpl/menu.php') ?> </div> <div id="kontener"> <?php if (isset($_SESSION['user_id']) and isset($_SESSION['login'])) { if(isset($_POST['submit_obrazek']) and $_GET['co']=='obrazek') { if(!$_POST['tytul'] || !$_FILES['obrazek']['name']) { echo '<b>Nie wypełniono pola z tytułem lub obrazkiem!</b><br/><a href="dodaj.php">« Powrót</a>'; } else { //UPLOAD OBRAZKA $sp1 = explode(".",($_FILES['obrazek']['name'])); if($sp1[1] == "gif" or $sp1[1] == "jpg" or $sp1[1] == "JPG" or $sp1[1] == "GIF" or $sp1[1] == "jpeg" or $sp1[1] == "JPEG" or $sp1[1] == "png" or $sp1[1] == "PNG") { $data_img=date('dmYHis'); $uploaddir = 'img/upload/'.$data_img.'-'; $_FILES['obrazek']['name'] = przyjazny_string($_FILES['obrazek']['name']); if(move_uploaded_file($_FILES['obrazek']['tmp_name'], $uploaddir.$_FILES['obrazek']['name'])) { //Zmiana rodzielczości obrazka if($sp1[1] != "gif" AND $sp1[1]!= "GIF") { $image = new SimpleImage(); $image->load($uploaddir.$_FILES['obrazek']['name']); if($image->getWidth() > 670) { $image->resizeToWidth(670); $image->save($uploaddir.$_FILES['obrazek']['name']); } else { //Zmiana wielkości do tego samego rozmiaru ale z kompresją $image->resizeToWidth($image->getWidth()); $image->save($uploaddir.$_FILES['obrazek']['name']); } } ////////////////////////////// $obrazek='img/upload/'.$data_img.'-'.$_FILES['obrazek']['name']; $tytul=htmlspecialchars($_POST['tytul']); $zrodlo=htmlspecialchars($_POST['zrodlo']); $autor=$_SESSION['login']; $data=date('Y-m-d H:i:s'); $zapytanie = "INSERT INTO `shity` (`id`, `tytul`, `obrazek`, `zrodlo`, `autor`, `data`, `typ`) VALUES ('', '$tytul', '$obrazek', '$zrodlo', '$autor', '$data', 'obrazek')"; $wykonaj = mysql_query($zapytanie); echo '<b>Obrazek został pomyślnie dodany!</b><br/> <a href="index.php">« Strona Główna</a>'; } else { echo '<b>Wystąpił błąd podczas dodawania obrazka.</b><br>'; echo '<a href="dodaj.php">« Powrót</a>'; } } else { echo '<b>Nie wybrano żadnego obrazka bądź jego format jest niedozwolony!</b><br/><a href="dodaj.php">« Powrót</a>'; } //KONIEC UPLOAD OBRAZKA } } else { ?>
<?php if($_GET['co']=='obrazek' || !$_GET['co']) { ?> <div id="tab_linia"></div> <form action="dodaj.php?co=obrazek" method="post" enctype="multipart/form-data"> <table> <colgroup> <col width="120px;"> <col> </colgroup> <tbody><tr> <td>Tytuł:</td> <td> <input class="pole" type="text" name="tytul"> </td> </tr> <tr> <td>Obrazek:</td> <td> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $ustawienia['max_file_size']*1024; ?>" /> <!--maksymalna wielkość pliku w bajtach--> <input name="obrazek" type="file" /> <span style="color:#595959">(max. <?php echo $ustawienia['max_file_size']; ?>KB)</span> </td> </tr> <tr> <td>Źródło:</td> <td><input class="pole" type="tekst" name="zrodlo"></td> </tr> <tr> <td></td> <td> <input type="submit" name="submit_obrazek" class="button" value="Dodaj" /> </td> </tr> </tbody></table> </form> <?php } else { if(isset($_POST['submit_film']) and $_GET['co']=='film') { if(!$_POST['tytul_filmu'] || !$_POST['adres_filmu']) { echo '<b>Nie wypełniono pola z tytułem lub adresem filmu!</b><br/><a href="dodaj.php?co=film">« Powrót</a>'; } else { if (preg_match("(http://)", $_POST['adres_filmu'])) { $tytul=$_POST['tytul_filmu']; $adres_filmu=trim($_POST['adres_filmu']); $autor=$_SESSION['login']; $data=date('d-m-Y H:i'); $zapytanie = "INSERT INTO `shity` (`id`, `tytul`, `obrazek`, `zrodlo`, `autor`, `data`, `typ`) VALUES ('', '$tytul', '$adres_filmu', 'YouTube', '$autor', '$data', 'film')"; $wykonaj = mysql_query($zapytanie); echo '<b>Filmik został pomyślnie dodany!</b><br/> <a href="index.php">« Strona Główna</a>'; } else { echo '<b>Link do filmu jest niepoprawny.</b><br/><a href="dodaj.php?co=film">« Powrót</a>'; } } } else { ?> <div id="tab_linia"></div> <form action="dodaj.php?co=film" method="post" enctype="multipart/form-data"> <table> <colgroup> <col width="120px;"> <col> </colgroup> <tbody><tr> <td>Tytuł:</td> <td> <input class="pole" type="text" name="tytul_filmu"> </td> </tr> <tr> <td>Adres filmu:</td> <td> <input class="pole" type="text" name="adres_filmu"> <span style="color:#595959">np. http://www.youtube.com/watch?v=7BfGua1Hn-8</span> </td> <tr> <td></td> <td> <input type="submit" name="submit_film" class="button" value="Dodaj" /> </td> </tr> </tbody></table> </form> <?php } } } } else { echo 'Aby dodać nowy obrazek musisz być zalogowany.<br/><br/> <a href="login.php" class="button" style="float:left;">Logowanie</a> <a href="rejestracja.php" class="button" style="margin-left:10px;float:left;">Rejestracja</a> <div style="clear:left;"></div>'; } ?> </div> <div id="stopka"> <?php include('tpl/stopka.php') ?> </div>
</body> </html> <?php ob_end_flush(); ?>
Kod PHP: <tr> <td>Obrazek:</td> <td> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $ustawienia['max_file_size']*1024; ?>" /> <!--maksymalna wielkość pliku w bajtach--> <input name="obrazek" type="file" /> <span style="color:#595959">(max. <?php echo $ustawienia['max_file_size']; ?>KB)</span> </td> </tr>
Chciałbym aby to pole było opcjonalne.Prosze o pomoc.
RE: Formularz - Pedro84 - 29-01-2012
Usuń sprawdzanie tablicy $_FILES z tego if'a: if(!$_POST['tytul'] || !$_FILES['obrazek']['name']) {
Dodatkowo, poniżej sprawdzaj czy tablica $_FILES istnieje.
RE: Formularz - Gekku - 29-01-2012
(29-01-2012, 05:17)Pedro84 napisał(a): Usuń sprawdzanie tablicy $_FILES z tego if'a: if(!$_POST['tytul'] || !$_FILES['obrazek']['name']) {
Dodatkowo, poniżej sprawdzaj czy tablica $_FILES istnieje.
Mógłbyś powiedzieć co jeszcze dokładnie usunąć bo ja już próbowałem dużo rzeczy usuwać i nic
RE: Formularz - Gekku - 30-01-2012
@odświeżam
RE: Formularz - Gekku - 04-02-2012
@ pomoże ktoś?
RE: Formularz - Pedro84 - 05-02-2012
Sprawdzanie tablicy: isset()
Usunięcie if'a: usuń od if() do else()
Po prostu zamień tego ifa z issetem sprawdzającym tablicę.
RE: Formularz - Gekku - 05-02-2012
Usunąłem Kod PHP: if(isset($_POST['submit_obrazek']) and $_GET['co']=='obrazek') { if(!$_POST['tytul'] || !$_FILES['obrazek']['name']) { echo '<b>Nie wypełniono pola z tytułem lub obrazkiem!</b><br/><a href="dodaj.php">« Powrót</a>'; }
i wyskoczył błąd
Kod: Parse error: syntax error, unexpected T_ELSE in on line 23
RE: Formularz - Pedro84 - 05-02-2012
http://pl.wikibooks.org/wiki/PHP/Instrukcja_if
RE: Formularz - Gekku - 05-02-2012
Usunąłem klamrę która kończyła Kod PHP: if(isset($_POST['submit_obrazek']) and $_GET['co']=='obrazek') {
RE: Formularz - Gekku - 08-02-2012
@odświeżam
Kod PHP: <?php /* Projekt: shitIMGv2 * Plik: dodaj.php * Data modyfikacji: 01-08-2011 * * Copyright (C) 2011 Paweł Klockiewicz & Wojciech Król * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ session_start(); //start sesji ob_start(); require_once('connect.php'); require_once('functions.php'); ?> <html> <head> <title><?php echo $ustawienia['tytul']; ?> - Dodaj obrazek</title> <?php include('tpl/head.php') ?> </head> <body> <div id="naglowek"> <!-- code by klocek & Quik --> <?php include('tpl/naglowek.php') ?> </div> <div id="menu"> <?php include('tpl/menu.php') ?> </div> <div id="kontener"> <?php if (isset($_SESSION['user_id']) and isset($_SESSION['login'])) { if (isset($_POST['submit_obrazek']) and $_GET['co'] == 'obrazek') { if (!$_POST['tytul']) { echo '<b>Nie wypełniono pola z tytułem!</b><br/><a href="dodaj.php">« Powrót</a>'; } else { //UPLOAD OBRAZKA if (isset($_FILES['obrazek']['name'])) { $sp1 = explode(".", ($_FILES['obrazek']['name'])); if ($sp1[1] == "gif" or $sp1[1] == "jpg" or $sp1[1] == "JPG" or $sp1[1] == "GIF" or $sp1[1] == "jpeg" or $sp1[1] == "JPEG" or $sp1[1] == "png" or $sp1[1] == "PNG") { $data_img = date('dmYHis'); $uploaddir = 'img/upload/' . $data_img . '-'; $_FILES['obrazek']['name'] = przyjazny_string($_FILES['obrazek']['name']); if (move_uploaded_file($_FILES['obrazek']['tmp_name'], $uploaddir . $_FILES['obrazek']['name'])) { //Zmiana rodzielczości obrazka if ($sp1[1] != "gif" AND $sp1[1] != "GIF") { $image = new SimpleImage(); $image->load($uploaddir . $_FILES['obrazek']['name']); if ($image->getWidth() > 670) { $image->resizeToWidth(670); $image->save($uploaddir . $_FILES['obrazek']['name']); } else { //Zmiana wielkości do tego samego rozmiaru ale z kompresją $image->resizeToWidth($image->getWidth()); $image->save($uploaddir . $_FILES['obrazek']['name']); } } ////////////////////////////// $obrazek = 'img/upload/' . $data_img . '-' . $_FILES['obrazek']['name']; $tytul = htmlspecialchars($_POST['tytul']); $zrodlo = htmlspecialchars($_POST['zrodlo']); $autor = $_SESSION['login']; $data = date('Y-m-d H:i:s'); $zapytanie = "INSERT INTO `shity` (`id`, `tytul`, `obrazek`, `zrodlo`, `autor`, `data`, `typ`) VALUES ('', '$tytul', '$obrazek', '$zrodlo', '$autor', '$data', 'obrazek')"; $wykonaj = mysql_query($zapytanie); echo '<b>Obrazek został pomyślnie dodany!</b><br/> <a href="index.php">« Strona Główna</a>'; } else { echo '<b>Wystąpił błąd podczas dodawania obrazka.</b><br>'; echo '<a href="dodaj.php">« Powrót</a>'; } } else { echo '<b>Nie wybrano żadnego obrazka bądź jego format jest niedozwolony!</b><br/><a href="dodaj.php">« Powrót</a>'; } //KONIEC UPLOAD OBRAZKA }
} } else { ?>
<?php if ($_GET['co'] == 'obrazek' || !$_GET['co']) { ?> <div id="tab"> <ul> <li id="selected"><a href="dodaj.php?co=obrazek"><img src="img/photo.png" style="position:relative;top:3px;"/> Dodaj Obrazek</a></li> <li><a href="dodaj.php?co=film"><img src="img/film.png" style="position:relative;top:3px;"/> Dodaj filmik z YouTube</a></li> </ul> </div> <div id="tab_linia"></div> <form action="dodaj.php?co=obrazek" method="post" enctype="multipart/form-data"> <table> <colgroup> <col width="120px;"> <col> </colgroup> <tbody><tr> <td>Tytuł:</td> <td> <input class="pole" type="text" name="tytul"> </td> </tr> <tr> <td>Obrazek:</td> <td> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $ustawienia['max_file_size'] * 1024; ?>" /> <!--maksymalna wielkość pliku w bajtach--> <input name="obrazek" type="file" /> <span style="color:#595959">(max. <?php echo $ustawienia['max_file_size']; ?>KB)</span> </td> </tr> <tr> <td>Źródło:</td> <td><input class="pole" type="tekst" name="zrodlo"></td> </tr> <tr> <td></td> <td> <input type="submit" name="submit_obrazek" class="button" value="Dodaj" /> </td> </tr> </tbody></table> </form> <?php } else { if (isset($_POST['submit_film']) and $_GET['co'] == 'film') { if (!$_POST['tytul_filmu'] || !$_POST['adres_filmu']) { echo '<b>Nie wypełniono pola z tytułem lub adresem filmu!</b><br/><a href="dodaj.php?co=film">« Powrót</a>'; } else { if (preg_match("(http://)", $_POST['adres_filmu'])) { $tytul = $_POST['tytul_filmu']; $adres_filmu = trim($_POST['adres_filmu']); $autor = $_SESSION['login']; $data = date('d-m-Y H:i');
$zapytanie = "INSERT INTO `shity` (`id`, `tytul`, `obrazek`, `zrodlo`, `autor`, `data`, `typ`) VALUES ('', '$tytul', '$adres_filmu', 'YouTube', '$autor', '$data', 'film')"; $wykonaj = mysql_query($zapytanie); echo '<b>Filmik został pomyślnie dodany!</b><br/> <a href="index.php">« Strona Główna</a>'; } else { echo '<b>Link do filmu jest niepoprawny.</b><br/><a href="dodaj.php?co=film">« Powrót</a>'; } } } else { ?> <div id="tab"> <ul> <li><a href="dodaj.php?co=obrazek"><img src="img/photo.png" style="position:relative;top:3px;"/> Dodaj Obrazek</a></li> <li id="selected"><a href="dodaj.php?co=film"><img src="img/film.png" style="position:relative;top:3px;"/> Dodaj filmik z YouTube</a></li> </ul> </div> <div id="tab_linia"></div> <form action="dodaj.php?co=film" method="post" enctype="multipart/form-data"> <table> <colgroup> <col width="120px;"> <col> </colgroup> <tbody><tr> <td>Tytuł:</td> <td> <input class="pole" type="text" name="tytul_filmu"> </td> </tr> <tr> <td>Adres filmu:</td> <td> <input class="pole" type="text" name="adres_filmu"> <span style="color:#595959">np. http://www.youtube.com/watch?v=7BfGua1Hn-8</span> </td> <tr> <td></td> <td> <input type="submit" name="submit_film" class="button" value="Dodaj" /> </td> </tr> </tbody></table> </form> <?php } } } } else { echo 'Aby dodać nowy obrazek musisz być zalogowany.<br/><br/> <a href="login.php" class="button" style="float:left;">Logowanie</a> <a href="rejestracja.php" class="button" style="margin-left:10px;float:left;">Rejestracja</a> <div style="clear:left;"></div>'; } ?> </div> <div id="stopka"> <?php include('tpl/stopka.php') ?> </div>
</body> </html> <?php ob_end_flush(); ?>
mam taki kod teraz wyświetla mi teraz komunikat
Cytat:Nie wybrano żadnego obrazka bądź jego format jest niedozwolony!
co teraz musze zrobić?
|