ziedinjsh Posted July 16, 2012 Report Share Posted July 16, 2012 (edited) php kods <meta charset="utf-8" /> <?php error_reporting(E_ALL); function create_thumbnail($source, $destination, $thumb_width){ $size = getimagesize($source); $width = $size[0]; $height = $size[1]; $x = 0; $y = 0; if($width > $height){ $x = ceil(($width - $height) /2); $width = $height; }elseif($height > $width){ $y = ceil(($height - $width) /2); $height = $width; } $new_image = imagecreatetruecolor($thumb_width, $thumb_width) or die("Ups!"); $extension = get_iamge_extension($source); if($extension=="jpg" || $extension=="jpeg") $image = imagecreatefromjpeg($source); if($extension=="gif") $image = imagecreatefromgif($source); if($extension=="png") $image = imagecreatefrompng($source); imagecopyresampled($new_image, $image, 0, 0, $x, $y, $tumb_width, $thumb_width, $width, $height); if($extension=="jpg" || $extension=="jpeg") imagejpeg($new_image,$destination); if($extension=="gif") imagegif($new_iamge,$destination); if($extension=="png") imagepng($new_image,$destination); } function get_image_extension($name){ $name = strtolower($name); $i = strrpos($name, "."); if(!$i) { return "";} $l = strlen($name) - $i; $extension = substr($name, $i, $l); return $extension; } function random_name($length){ $characters = "1234567890"; $name = ""; for($i = 0; $i < $length; $i++){ $name .= $characters[mt_rand(0, strlen($characters) - 1)]; } return $name; } $big = "../wall/"; $small = "../wall/small/"; $small_width = 70; $max_size = 50000000; $results = "Izvelies bildi!"; if(empty($_FILES['photo']['name'])){ $results = "Bildes lauciņš ir tukšs!"; }else{ $size = filesize($_FILES['photo']['tmp_name']); $filename = stripslashes($_FILES['photo']['name']); $extension = get_image_extension($filename); if($size > $max_size){ $results = "Bilde ir pārāk liela!"; }else if( ($extension !=".jpg") && ($extension !=".jpeg") && ($extension !=".png") && ($extension !=".gif") ){ $results = "Izvēlies tikai *.jpeg, *.jpg, *.png un *.gif formāta bildes!"; }else{ $image_random_name = random_name(15).".".$extension; $copy = @copy($_FILES['photo']['tmp_name'], $big.$images_random_name); if(!$copy){ $results = "Augšupielādes kļūda, meiģini vēlreiz."; }else{ create_thumbnail($big.$images_random_name, $small.$image_random_name, $small_width); $results = "Bilde ir augšupielādēta!"; } } } echo $results; ?> Kad izvelos bildi un postoju formu man visu laiku izmet šādu results: Augšupielādes kļūda, meiģini vēlreiz. kas pa vainu? Edited July 16, 2012 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
briedis Posted July 16, 2012 Report Share Posted July 16, 2012 Āizvāc to @ zīmi. NEKAD viņu vairs neizmanto! Quote Link to comment Share on other sites More sharing options...
daGrevis Posted July 17, 2012 Report Share Posted July 17, 2012 Vaina? `@copy($_FILES['photo']['tmp_name'], $big.$images_random_name);` Dod atpakaļ _falsy_ mainīgo. Debuggo un meklē kāpēc! Quote Link to comment Share on other sites More sharing options...
blackhalt Posted July 18, 2012 Report Share Posted July 18, 2012 Es netestēju, bet http://lv.php.net/manual/en/function.move-uploaded-file.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.