Jump to content
php.lv forumi

bildes augšuplāde skripts


Niko222

Recommended Posts

Nezinu vai kods ir pareizi uztaisīts bet kas varētu būt pa vainu man bilde nelādējas un neparādas kur viņai vaidzētu būt.

 

<?php
session_start();
include('inc/config.php');
include('inc/functions.php');
if(isset($_SESSION['user_id'])){
$change="";
$abc="";
if($_FILES['file']){
define ("MAX_SIZE","5000");
function getExtension($str) {
		$i = strrpos($str,".");
		if (!$i) { return ""; }
		$l = strlen($str) - $i;
		$ext = substr($str,$i+1,$l);
		return $ext;
}
$errors=0;
 $image =$_FILES["file"]["name"];
$uploadedfile = $_FILES['file']['tmp_name'];


 if ($image)
 {

  $filename = stripslashes($_FILES['file']['name']);

$extension = getExtension($filename);
  $extension = strtolower($extension);


if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "psd"))
  {

$change='<div class="msgdiv">Kļūda! Nezināms bildes formāts</div> ';
$errors=1;
  }
  else
  {
$size=filesize($_FILES['file']['tmp_name']);

if ($size > MAX_SIZE*1024)
{
$change='<div class="msgdiv">Jūs pārsniedzāt bildes izmēra limitu (MB)</div> ';
$errors=1;
}

if($extension=="jpg" || $extension=="jpeg" )
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
}
else if($extension=="png")
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefrompng($uploadedfile);
}
else
{
$src = imagecreatefromgif($uploadedfile);
}
echo $scr;
list($width,$height)=getimagesize($uploadedfile);

$newwidth=150;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);

$newwidth1=50;
$newheight1=($height/$width)*$newwidth1;
$tmp1=imagecreatetruecolor($newwidth1,$newheight1);
$orgwidth=$width;
$orgheight=($height/$width)*$orgwidth;
$org=imagecreatetruecolor($orgwidth,$orgheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);
imagecopyresampled($org,$src,0,0,0,0,$orgwidth,$orgheight,$width,$height);

$time = time();
$filename = "images/thumb_".$time."_". $_FILES['file']['name'];
$profile_photo_url = $time."_". $_FILES['file']['name'];
$filename1 = "images/small_".$time."_". $_FILES['file']['name'];
$orginal = "images/".$time."_". $_FILES['file']['name'];
imagejpeg($tmp,$filename,100);
imagejpeg($tmp1,$filename1,100);
imagejpeg($org,$orginal,100);
function watermarkImage($location)
{
$imagesource =  $location;
$filetype = substr($imagesource,strlen($imagesource)-4,4);
$filetype = strtolower($filetype);
if($filetype == ".gif")  $image = @imagecreatefromgif($imagesource);
if($filetype == ".jpg")  $image = @imagecreatefromjpeg($imagesource);
if($filetype == ".png")  $image = @imagecreatefrompng($imagesource);
if (!$image) die();
$watermark = @imagecreatefrompng(K_small_logo_watermark.png');
$imagewidth = imagesx($image);
$imageheight = imagesy($image);
$watermarkwidth =  imagesx($watermark);
$watermarkheight =  imagesy($watermark);
$size = getimagesize($location);
$differenceX = $imagewidth - $watermarkwidth;
$placementX =  round($differenceX / 2);
$y_pos = $size[1] - $watermarkheight - 10;
imagecopy($image, $watermark, $placementX, $y_pos, 0, 0, $watermarkwidth, $watermarkheight);
imagejpeg($image, $location);
}
//Izsauc Funkciju
watermarkImage($orginal);
mysql_query("UPDATE lietotaji SET profile_photo='".$profile_photo_url."' WHERE user_id='".intval($_SESSION['user_id'])."'");
mysql_query("DELETE FROM rate WHERE id='profile".intval($_SESSION['user_id'])."'");
 $suc='Bilde augšupielādēta veiksmīgi!';
echo '<script type="text/javascript">
var data = "'.$suc.'";
parent.myCallBackFunction(data);
  </script>';
imagedestroy($src);
imagedestroy($tmp);
imagedestroy($tmp1);
imagedestroy($org);
}
}
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
.bx {
background-color: #F3F3F3;
border: 1px solid #CCC;
border-bottom-left-radius: 7px 7px;
border-bottom-right-radius: 7px 7px;
border-top-left-radius: 7px 7px;
border-top-right-radius: 7px 7px;
margin-bottom: 10px;
padding: 7px 10px;
position: relative;
zoom: 1;
}
</style>
<div class="bx">
<center>
<b><font color="red">Profila bildē ir jābūt redzamam tev!</font></b><br/>
<font color="red">Tev ir jābūt skaidri saskatāmam un atpazīstamam.</font><br/>
</center>
<br/>
<center>
<div style="width: 470px;  background: #eee; border: 1px solid #ccc;">
<form action="change_foto.php" enctype="multipart/form-data" method="post" target="iframe">
<b>Bilde: </b><input size="10" name="file" type="file" value="Izvēlēties"/><br />
(Ieteicams .jpg bildes formāts)<br/><br/>
<input type="submit" value="Augšupielādet" />
<iframe name="iframe" style="display:none;"></iframe>
</form>
</div>
</center>
<script>
function myCallBackFunction(data)
{
 //put your code here
 alert(data);
}
</script>
<?php } else { error("Lai mainītu bildi, jums ir jāautorizējas!"); }?>

Link to comment
Share on other sites

Posms #1: success!

 

Tālāk domā kāpēc notiek tas:

 

> [..] bet neaiziet uz norādīto vietu kur viņai jāaiziet būtu jāaiziet..

 

Vai arī tu domā, ka kāds no šejieniešiem ņemsies ar tavu 162 rindiņas garo HTML/CSS/JavaScript/PHP/SQL "koda" blāķi? (:

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...