Jump to content
php.lv forumi

augšupielādēšana/ kopēšana


ziedinjsh

Recommended Posts

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 by ziedinjsh
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...