samanti Δημοσ. 21 Οκτωβρίου 2010 Δημοσ. 21 Οκτωβρίου 2010 Παρακάτω είναι ο κώδικας για το ανέβασμα μιας εικόνας .png ή .jpg και για την δημιουργία του thumbnail της. To πρόβλημα είναι οτι δεν αποθηκεύει το thumbnail στο δηλωμένο path "/../../thumbs", όπως και περίεργο είναι ότι το script δούλευει σε άλλο path το οποίο είναι σε διαφορετικό tree και level (ενοείται οτι ο owner και τα file privileges είναι τα ίδια). Πιθανόν να είναι κάτι που δεν έχω αντιληφθεί ή κάπου κάνω κάτι λάθος. Θα ήθελα τη βοήθεια σας. Ευχαριστω εκ των προτέρων. > function a_upload (){ $thumb_width = 120; $thumb_height = 120; $imgdir = '../images/gallery/'; $dimg = opendir($imgdir); $pro_img_name = basename( $_FILES['uploadedfile']['name']); $img_path = $imgdir . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $img_path)) { $thumb = createthumb($img_path, $thumb_width, $thumb_height); $thumb_imgdir = '../images/gallery/thumbs/'; $thumb_img_name = substr_replace($pro_img_name, '_thumb', -4, 0); $thumb_img_path = $thumb_imgdir.$thumb_img_name; //echo $thumb_img_path; die(); $array=explode('.',$img_path); // print_r($array); die(); if (preg_match('/jpg|jpeg/',$array[1])){ imagejpeg($thumb, $thumb_img_path, 100) ; } if (preg_match('/png/',$array[1])){ imagepng($thumb, $thumb_img_path, 100) ; } go('index.php?page=photos'); } else { echo "Fail!!!, please <a href=\"index.php?page=photos\">try again!</a>"; } } function createthumb ($img_path, $thumb_width, $thumb_height){ list ($img_width, $img_height) = getimagesize($img_path); $xscale = $img_width/$thumb_width; $yscale = $img_height/$thumb_height; if ($yscale>$xscale){ //echo "yscale>xsclae"; $new_width = round($img_width * (1/$yscale)); $new_height = round($img_height * (1/$yscale)); }else { $new_width = round($img_width * (1/$xscale)); $new_height = round($img_height * (1/$xscale)); } $image_thumb = imagecreatetruecolor($new_width, $new_height); $system=explode('.',$img_path); if (preg_match('/jpg|jpeg/',$system[1])){ $image_tmp=imagecreatefromjpeg($img_path); //print_r ($new_image); die(); } if (preg_match('/png/',$system[1])){ $image_tmp=imagecreatefrompng($img_path); } imagecopyresampled($image_thumb, $image_tmp, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height); return $image_thumb; }
samanti Δημοσ. 21 Οκτωβρίου 2010 Μέλος Δημοσ. 21 Οκτωβρίου 2010 Παρακάτω είναι ο κώδικας για το ανέβασμα μιας εικόνας .png ή .jpg και για την δημιουργία του thumbnail της. To πρόβλημα είναι οτι δεν αποθηκεύει το thumbnail στο δηλωμένο path "/../../thumbs", όπως και περίεργο είναι ότι το script δούλευει σε άλλο path το οποίο είναι σε διαφορετικό tree και level (ενοείται οτι ο owner και τα file privileges είναι τα ίδια). Πιθανόν να είναι κάτι που δεν έχω αντιληφθεί ή κάπου κάνω κάτι λάθος. Θα ήθελα τη βοήθεια σας. Ευχαριστω εκ των προτέρων. > function a_upload (){ $thumb_width = 120; $thumb_height = 120; $imgdir = '../images/gallery/'; $dimg = opendir($imgdir); $pro_img_name = basename( $_FILES['uploadedfile']['name']); $img_path = $imgdir . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $img_path)) { $thumb = createthumb($img_path, $thumb_width, $thumb_height); $thumb_imgdir = '../images/gallery/thumbs/'; $thumb_img_name = substr_replace($pro_img_name, '_thumb', -4, 0); $thumb_img_path = $thumb_imgdir.$thumb_img_name; //echo $thumb_img_path; die(); $array=explode('.',$img_path); // print_r($array); die(); if (preg_match('/jpg|jpeg/',$array[1])){ imagejpeg($thumb, $thumb_img_path, 100) ; } if (preg_match('/png/',$array[1])){ imagepng($thumb, $thumb_img_path, 100) ; } go('index.php?page=photos'); } else { echo "Fail!!!, please <a href=\"index.php?page=photos\">try again!</a>"; } } function createthumb ($img_path, $thumb_width, $thumb_height){ list ($img_width, $img_height) = getimagesize($img_path); $xscale = $img_width/$thumb_width; $yscale = $img_height/$thumb_height; if ($yscale>$xscale){ //echo "yscale>xsclae"; $new_width = round($img_width * (1/$yscale)); $new_height = round($img_height * (1/$yscale)); }else { $new_width = round($img_width * (1/$xscale)); $new_height = round($img_height * (1/$xscale)); } $image_thumb = imagecreatetruecolor($new_width, $new_height); $system=explode('.',$img_path); if (preg_match('/jpg|jpeg/',$system[1])){ $image_tmp=imagecreatefromjpeg($img_path); //print_r ($new_image); die(); } if (preg_match('/png/',$system[1])){ $image_tmp=imagecreatefrompng($img_path); } imagecopyresampled($image_thumb, $image_tmp, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height); return $image_thumb; }
Προτεινόμενες αναρτήσεις
Αρχειοθετημένο
Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.