![]() |
![]() ![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 3 Pomógł: 0 Dołączył: 20.09.2009 Ostrzeżenie: (0%) ![]() ![]() |
Witam serdecznie,
mam problem ze swoim skryptem. Chciałbym napisać uploader'a obrazków. Problem jest taki, że gdy includuje plik z funkcjami, łączę się z MySQL, pobieram adres obrazka z bazy, skaluję obrazek za pomocą biblioteki GD, wysyłam odpowiedni obrazek nic nie otrzymuję, jednak gdy usunę Header(... ...) ze skryptu krzaczki są widoczne. Zauważyłem, że gdy zapiszę pustą stronę na dysk, a następnie ją otworze np. notatnikiem otrzymuje: Kod <b>Warning</b>: imagejpeg(): supplied argument is not a valid Image resource in <b>/home/the/public_html/photer/function.php</b> on line <b>100</b><br /> Problem zanika, gdy w jednym pliku umieszczę konfigurację MySQL i funkcję łączenia z bazą. Plik mający za zadanie wyświetlić i zeskalować obrazek: Kod <?php ob_start(); include('function.php'); SQLConnect(); $x_scale = 500; ImageResizer(GetFilenameFromMySQL(), 'show', $x_scale); SQLDisconnect(); ob_end_flush(); ?> Użyte funkcje z pliku function.php: Kod function SQLConnect($dbname = DB_NAME, $dbhost = DB_HOST, $dbuser = DB_USERNAME, $dbpass = DB_PASSWORD) { $baza = mysql_connect($dbhost, $dbuser, $dbpass); if(!$baza) { return false; include('error.php?error=mysql_error'); } else { mysql_select_db($dbname); return true; } } function SQLDisconnect() { mysql_close(); } function GetFilenameFromMySQL() { $sql = 'SELECT name FROM '.DB_TABLE.' WHERE hash="'.$_GET['z'].'"'; $pytanie = mysql_query($sql); $row = mysql_fetch_assoc($pytanie); $imgname = $row['name']; return $imgname; } function getImage($imgname) { $ext = substr($imgname, strlen($imgname) - 3, 3); $ext = strtolower($ext); if($ext == 'jpg') { $img = imagecreatefromjpeg($imgname); $GLOBALS['img_type'] = IMG_JPEG; } else if($ext == 'gif') { $img = imagecreatefromgif($imgname); $GLOBALS['img_type'] = IMG_GIF; } else if($ext == 'png') { $img = imagecreatefrompng($imgname); $GLOBALS['img_type'] = IMG_PNG; } else { $img = null; $GLOBALS['img_type'] = null; } return $img; } function SaveImage($img, $imgname) { switch($GLOBALS['img_type']) { case IMG_JPEG: $imagejpeg($img, $imgname); break; case IMG_GIF: imagegif($img, $imgname); break; case IMG_PNG: imagepng($img, $imgname); break; } } function ShowImage($img) { switch($GLOBALS['img_type']) { case IMG_JPEG: header('Content-type: image/jpeg'); imagejpeg($img); ImageDestroy($img); break; case IMG_GIF: header('Content-type: image/gif'); imagegif($img); break; case IMG_PNG: header('Content-type: image/png'); imagepng($img); break; } } function ImageResizer($imgname, $function, $new_width = 0) { if(!($img = getImage($imgname))) { include('error.php?msg=file_error'); exit; } if($new_width = 0) { $img_w = imagesx($img); $img_h = imagesy($img); $ratio = $img_w / $img_h; if($ratio > 1) { $new_img_w = $new_width; $new_img_h = ($new_width / $ratio); } else { $new_img_w = ($new_width * $ratio); $new_img_h = $new_width; } $tempImg = imagecreatetruecolor($new_img_w, $new_img_h); imagecopyresized($tempImg, $img, 0, 0, 0, 0, $new_img_w, $new_img_h, $img_w, $img_h); } if($function == 'show') ShowImage($tempImg, $imgname); elseif($function == 'save') SaveImage($tempImg, $imgname); } Serwer obsługuje GD, adres obrazka na pewno jest pobierany z bazy. Byłbym wdzięczny za pomoc ![]() |
|
|
![]()
Post
#2
|
|
![]() Grupa: Moderatorzy Postów: 15 467 Pomógł: 1451 Dołączył: 25.04.2005 Skąd: Szczebrzeszyn/Rzeszów ![]() |
A co jest w tej 100. linijce?
-------------------- ![]() ZCE :: Pisząc PW załączaj LINK DO TEMATU i TYLKO w sprawach moderacji :: jakiś błąd - a TREŚĆ BŁĘDU? :: nie ponaglaj z odpowiedzią via PW! |
|
|
![]()
Post
#3
|
|
Grupa: Zarejestrowani Postów: 3 Pomógł: 0 Dołączył: 20.09.2009 Ostrzeżenie: (0%) ![]() ![]() |
|
|
|
![]() ![]() |
![]() |
Aktualny czas: 21.08.2025 - 08:06 |