0
function zapisz_plik($key, $numer)
{
    global $nazwa_pliku;
    global $ostatni;

    $filess = glob("./../glowna_img/slide$numer*.jpg");
    if (is_array($filess) && count($filess) > 0) {
        foreach ($filess as $filename) {
            $files[] = $filename;
        }
    } 


    if (!empty($files)) {

    $ostatni = $files[count($files)-1];
    $pokaz_ostatni = explode("slide$numer-", $ostatni); 
    $ostatni_czysty = explode(".jpg", $pokaz_ostatni[1]); 
    $dodawanie = $ostatni_czysty[0] +1; 
    if (strlen($dodawanie) == 1) $dodawanie = '0'.$dodawanie; 
    $nazwa_pliku = "slide$numer-$numer_$dodawanie.jpg";
    $lokalizacja = "./../glowna_img/$nazwa_pliku";
    }
    else {
        $nazwa_pliku = "slide$numer-01.jpg";
        $lokalizacja = "./../glowna_img/slide$numer-01.jpg";
    }


  if(is_uploaded_file($_FILES['obrazek']['tmp_name'][$key]))
  {
    list($width, $height) = getimagesize($_FILES['obrazek']['tmp_name'][$key]);
    if ($width <= 820 && $height <= 444)
    {
        if(!move_uploaded_file($_FILES['obrazek']['tmp_name'][$key], $lokalizacja))
        {
          echo 'problem: Nie udało się skopiować pliku do katalogu.';
            return false;  
        }
    }
    else {
        echo 'Plik jest za dużych rozmiarów, proszę wskazać plik o maksymalnym rozmiarze 820x444px';
        ****return false;****
    }
  }
  else
  {
    echo 'problem: Możliwy atak podczas przesyłania pliku.';
    echo 'Plik nie został zapisany.';
    return false;
  }
  return true;
}

This is my function for saving photos and one return doesn't want to work, exaccly this under this code:

echo 'Plik jest za dużych rozmiarów, proszę wskazać plik o maksymalnym rozmiarze 820x444px';

This is my code for using it.

if (isset($_POST['wyslij'])) {
    for($key=0; $key < count($_FILES['obrazek']); $key++) {
            if  (!empty($_FILES['obrazek']['name'][$key])) {
                if (sprawdz_bledy($key) && sprawdz_typ($key)) {
                    $numer = $key + 1;
                    zapisz_plik($key,$numer);
                    if (zapisz_plik == true) {
                        try{
                            $stmt = $pdo -> prepare("UPDATE Slider SET Nazwa = :nazwa WHERE ID = :ID ");
                            $stmt -> bindValue(':nazwa', $nazwa_pliku, PDO::PARAM_STR);
                            $stmt -> bindValue(':ID', $numer, PDO::PARAM_INT);
                            $stmt -> execute();

                        }catch(PDOException $e){
                            $display = 'Błąd zapytania:<br> ' . $e->getMessage();
                        }   
                        if (isset($ostatni)) unlink($ostatni);
                    }
                }
            }
    }
}

And this IF:

if (zapisz_plik == true) {

doesn't want to work.

When I try send photo with bad size (more than 820x444), I see error ECHO, but the IF change name in SQL.

Could you tell me why, this return doesn't want to work?

SkuterPL
  • 89
  • 1
  • 8

1 Answers1

0

in your code

if (zapisz_plik == true) {

zapisz_plik has no meaning. If you had display_errors turned on, which you always should have whilst developing, you would get a warning telling you this.

E_NOTICE : type 8 -- Use of undefined constant zapisz_plik - assumed 'zapisz_plik'

You need to check the return value

$return = zapisz_plik($key,$numer);
if ($return == true) {

or

if (zapisz_plik($key,$numer) == true) {
Anigel
  • 3,435
  • 1
  • 17
  • 23
  • oh, it was that easy, thanks you so much ;) Could you tell me how to you check the E_NOTICE? – SkuterPL Jul 08 '13 at 14:49
  • Your php.ini file contains options to display_errors and that can be on or off. I would suggest on for development and off for live servers. At the very least you should log_errors and check the error_log if you cannot display_errors. See http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php – Anigel Jul 08 '13 at 14:51
  • I have just checked my settings of server and I have turn on error_reporting = E_ALL & ~E_NOTICE; and display_errors = On, so why I didn't see this error like you? – SkuterPL Jul 08 '13 at 15:47
  • No idea sorry, try viewing page source code, maybe it is showing up there, maybe there is another setting somewhere disabling it. without having all your settings, htaccess and code, I can't begin to guess what may be disabling it – Anigel Jul 08 '13 at 15:58