Малко помощ със снимките

shaxaaa

Registered
Код:
<?php 

//connect to the database
$link = mysql_connect("localhost", "root", "")
  or die("Could not connect: " . mysql_error());
mysql_select_db("reklama", $link) 
  or die (mysql_error());

//make variables available 
$advert_message = $_POST['advert_message'];
$advert_user = $_POST['advert_user'];
if (empty($_FILES['image_filename']['name'])) {
$_FILES['image_filename']['name'] == "<img src=\"C:/Program Files/apachefriends/xampp/htdocs/reklama/pic.gif\">";
$image_tempname = $_FILES['image_filename']['name'];
} else {
$image_tempname = $_FILES['image_filename']['name'];
}
$advert_type = $_POST['advert_type'];
$advert_agree = $_POST['advert_agree'];
$today = date("Y-m-d H:i:s");
			
//upload image and check for image type
$ImageDir ="C:/Program Files/apachefriends/xampp/htdocs/reklama/images/";

$ImageThumb = $ImageDir . "thumbs/";

$ImageName = $ImageDir . $image_tempname;

if (move_uploaded_file($_FILES['image_filename']['tmp_name'], 
                      $ImageName)) {
					  
  //get info about the image being uploaded
  list($width, $height, $type, $attr) = getimagesize($ImageName);

  if ($type > 3) {
    echo "Ñúæåëÿâàìå íî ôàéëà òðÿáâà äà áúäå îò òèï JPEG,Gif " .
         "èëè PNG.<br>";
    echo "Ìîëÿ îïèòàéòå îòíîâî.";
	} else {
   //image is acceptable; ok to proceed

  //insert info into image table
  $advert_message = trim($_POST['advert_message']);
  if(empty($advert_message)) { $error .= "Ìîëÿ+âúâåäåòå+îáÿâà%21%0D%0A"; }
  if(empty($_POST['advert_user']))  { $error .="Ìîëÿ+âúâåäåòå+îò+êîé+å+îáÿâàòà%21%0D%0A"; }
  if(empty($_POST['advert_type'])) { $error .="Ìîëÿ+âúâåäåòå+òèï+íà+îáÿâàòà%21%0D%0A"; }
  if(empty($_POST['advert_agree'])) { $error .="Òðÿáâà+äà+ñòå+ñúãëàñíè+ñúñ+óñëîâèÿòà%21%0D%0A"; }
  if (empty($error)) {
  $insert = "INSERT INTO advert_post
            (advert_id, advert_message, advert_user, advert_date, advert_type, advert_agree)
            VALUES
            (NULL, '$advert_message', '$advert_user', '$today', '$advert_type', 'advert_agree')";
			} else {
			header("location:pusni_obqva.php?action=add&error=" . $error);
			}
			if (isset($insert) && !empty($insert)) {
			echo "<!--" .$insert. "--!>";
			?>
			<?php
		    }
  $insertresults = mysql_query($insert)
    or die(mysql_error());

  $lastpicid = mysql_insert_id();

  //change the following line:
  $newfilename =  $ImageDir . $lastpicid . ".jpg";

  if ($type == 2) {
    rename($ImageName, $newfilename);
  } else {
    if ($type == 1) {
      $image_old = imagecreatefromgif($ImageName);
    } elseif ($type == 3) {
      $image_old = imagecreatefrompng($ImageName);
    }

    //"convert" the image to jpg
    $image_jpg = imagecreatetruecolor($width, $height);
    imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, 
                     $width, $height, $width, $height);
    imagejpeg($image_jpg, $newfilename);
    imagedestroy($image_old);
    imagedestroy($image_jpg);
  }

  $newthumbname = $ImageThumb . $lastpicid . ".jpg";

  //get the dimensions for the thumbnail
  $thumb_width = 100;
  $thumb_height = 75;

  //create the thumbnail
  $largeimage = imagecreatefromjpeg($newfilename);
  $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
  imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0, 
                    $thumb_width, $thumb_height, $width, $height);
  imagejpeg($thumb, $newthumbname);
  imagedestroy($largeimage);
  imagedestroy($thumb);
  
  $url = "location: viewadvert.php?t=" . $lastpicid;
  header($url);
}
} 
?>
Тук се проверява една форма за попълване , където има да се слага снимка , но когато не се даде снимка ми изкарва бял екран и иска явно да се вкара снимка , как да го направя така че ако не е дал снимка да избира някаква моя снимка и да приема данните .
 
Нямам време да ти разглеждам кода и за това ще ти дам пример как да стане това което изкаш

Код:
if ($image == "")
{
$image = "images/nopic.jpg";
}

Ето това нещо проверява дали променливата image има стойност
  • Ако има стойноста се запазна
    Ако няма се задава стойност images/nopic.jpg
 
Пич тоси има такава опция


<?php

//connect to the database
$link = mysql_connect("localhost", "root", "")
or die("Could not connect: " . mysql_error());
mysql_select_db("reklama", $link)
or die (mysql_error());

//make variables available
$advert_message = $_POST['advert_message'];
$advert_user = $_POST['advert_user'];
if (empty($_FILES['image_filename']['name'])) {
$_FILES['image_filename']['name'] = "<img src=\"C:/Program Files/apachefriends/xampp/htdocs/reklama/pic.gif\">";
$image_tempname = $_FILES['image_filename']['name'];
} else {
$image_tempname = $_FILES['image_filename']['name'];
}
$advert_type = $_POST['advert_type'];
$advert_agree = $_POST['advert_agree'];
$today = date("Y-m-d H:i:s");

//upload image and check for image type
$ImageDir ="C:/Program Files/apachefriends/xampp/htdocs/reklama/images/";

$ImageThumb = $ImageDir . "thumbs/";

$ImageName = $ImageDir . $image_tempname;

if (move_uploaded_file($_FILES['image_filename']['tmp_name'],
$ImageName)) {

//get info about the image being uploaded
list($width, $height, $type, $attr) = getimagesize($ImageName);

if ($type > 3) {
echo "Nu?aeyaaia ii oaeea o?yaaa aa auaa io oei JPEG,Gif " .
"eee PNG.<br>";
echo "Iiey iieoaeoa ioiiai.";
} else {
//image is acceptable; ok to proceed

//insert info into image table
$advert_message = trim($_POST['advert_message']);
if(empty($advert_message)) { $error .= "Iiey+auaaaaoa+iayaa%21%0D%0A"; }
if(empty($_POST['advert_user'])) { $error .="Iiey+auaaaaoa+io+eie+a+iayaaoa%21%0D%0A"; }
if(empty($_POST['advert_type'])) { $error .="Iiey+auaaaaoa+oei+ia+iayaaoa%21%0D%0A"; }
if(empty($_POST['advert_agree'])) { $error .="O?yaaa+aa+noa+nuaeanie+nun+oneiaeyoa%21%0D%0A"; }
if (empty($error)) {
$insert = "INSERT INTO advert_post
(advert_id, advert_message, advert_user, advert_date, advert_type, advert_agree)
VALUES
(NULL, '$advert_message', '$advert_user', '$today', '$advert_type', 'advert_agree')";
} else {
header("location:pusni_obqva.php?action=add&error=" . $error);
}
if (isset($insert) && !empty($insert)) {
echo "<!--" .$insert. "--!>";
?>
<?php
}
$insertresults = mysql_query($insert)
or die(mysql_error());

$lastpicid = mysql_insert_id();

//change the following line:
$newfilename = $ImageDir . $lastpicid . ".jpg";

if ($type == 2) {
rename($ImageName, $newfilename);
} else {
if ($type == 1) {
$image_old = imagecreatefromgif($ImageName);
} elseif ($type == 3) {
$image_old = imagecreatefrompng($ImageName);
}

//"convert" the image to jpg
$image_jpg = imagecreatetruecolor($width, $height);
imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0,
$width, $height, $width, $height);
imagejpeg($image_jpg, $newfilename);
imagedestroy($image_old);
imagedestroy($image_jpg);
}

$newthumbname = $ImageThumb . $lastpicid . ".jpg";

//get the dimensions for the thumbnail
$thumb_width = 100;
$thumb_height = 75;

//create the thumbnail
$largeimage = imagecreatefromjpeg($newfilename);
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0,
$thumb_width, $thumb_height, $width, $height);
imagejpeg($thumb, $newthumbname);
imagedestroy($largeimage);
imagedestroy($thumb);

$url = "location: viewadvert.php?t=" . $lastpicid;
header($url);
}
}
?>


Самоче трябва да зададеш пътя по пози начин http://www.yoursite.bg/images/nopic.jpg
 
моля ви погледнете ми сорса и вижте в този сайт http://borsata.info/ads.php?cat=%C0%E2%F2%EE\%C0%E2%F2%EE%EC%EE%E1%E8%EB%E8 вижте където е thumba как излиза това фотоапаратче ако не пуснеш снимка поправете ми сорса че от 5 дена се мъча и немога да се справя моля ви се
 

Back
Горе