Hi
i have taken news script with image upload feature
it works fine.
it show image and its being getting smalled thumbnail at the right side
but when i added news without image instead of image it displays red instead of little (thumbnail) image X sign you can see script from here
you can go here http://aziko.6te.net/yukle/haber_ekle.php
and you can view the news you added from here http://aziko.6te.net/yukle/
here is full code
Thanks for attention
@azegurb
Index.php, lines #71 through #84. - This is where your HTML for the article headlines is being printed. This is what you need to change to replace/remove the thumbs that are broken.
The query fetches the article data from the database - and ignoring for now the fact that you are putting invalid links into the database in the first place - you need to simply verify that the image is valid before printing the <img> tag.
It's not all that complex. You just use the file_exists function on the image location and print the appropriate HTML based on what it returns.
Try it. Post your attempts here. (Just the alterations please, we don't need another 400 lines of code!)
8 2657 Atli 5,058
Expert 4TB
Hey.
You need to make sure there is an image attached to the article before you try to display it. - The file_exists function should help with that.
P.S.
It's generally best to write your code in English. Makes it more "portable".
It's not fun having to translate all your code because the people who ended up using it don't understand a word of it. (Trust me, I've been there xD)
Atli 5,058
Expert 4TB @azegurb
No need to do that on my account. It's just something to keep in mind. (I won't be reading all that code anyways.)
It would perhaps be best if you just posted the parts of the code you are having trouble with, and translated those so we can make sense of it.
image_add.php - <?php
-
function resample($image,$max_width,$max_height)
-
{
-
-
# Icerik icin kesi baslat ...
-
ob_start();
-
-
# Ilk heightutlar
-
$boyuut = getimagesize($image);
-
$width = $boyut[0];
-
$height = $boyut[1];
-
-
# new heightutlar
-
$x_oran = $max_width / $width;
-
$y_oran = $max_height / $height;
-
-
if (($width <= $max_width) and ($height <= $max_height)){
-
$son_width = $width;
-
$son_height = $height;
-
}
-
else if (($x_oran * $height) < $max_height){
-
$son_width = $max_width;
-
$son_height = ceil($x_oran * $height);
-
}
-
else {
-
$son_width = ceil($y_oran * $width);
-
$son_height = $max_height;
-
}
-
-
# old ve new imageler
-
$old = imagecreatefromjpeg($image);
-
$new = imagecreatetruecolor($son_width,$son_height);
-
-
# old image
-
imagecopyresampled(
-
$new,$old,0,0,0,0,
-
$son_width,$son_height,$width,$height);
-
-
# new image
-
imagejpeg($new,null,-1);
-
$icerik = ob_get_contwidthts();
-
-
-
ob_widthd_clean();
-
imagedestroy($old);
-
imagedestroy($new);
-
-
return $icerik;
-
-
}
-
?>
add_news.php - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9" />
-
<title>Dahi Tasarim</title>
-
<script type="text/JavaScript">
-
<!--
-
function MM_jumpMenu(targ,selObj,restore){ //v3.0
-
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
-
if (restore) selObj.selectedIndex=0;
-
}
-
//-->
-
</script>
-
</head>
-
-
<body>
-
<p>
-
<?
-
include("connect.php");
-
//include ("oturum_kontrol.php");
-
//include ("yonetim_menu.php");
-
include ("image_add.php");
-
?>
-
-
</p>
-
<p style="font-size:24pt; color:#FF0000;">Haber Ekle </p>
-
-
<hr />
-
News :
-
<? /
-
-
$no=$_POST[no];
-
$title=$_POST[title];
-
$subject=$_POST[subject];
-
$description=$_POST[description];
-
$aktiv=$_POST[aktiv];
-
$search=$_POST[search];
-
$show=$_POST[show];
-
-
// image settings
-
$little_pic="little_pictures"; // open this directory
-
$large_pic="large_pictures"; // and give permission chmod 777
-
-
$large_pic_width=640;
-
$large_pic_heigth=480;
-
-
$little_pic_width=200;
-
$little_pic_heigth=150;
-
-
-
-
//if ($image)
-
-
?>
-
<? if ($_POST[del])
-
{// if pressed del button
-
$query=mysql_query("select * from news where no='$no'");
-
while($row=mysql_fetch_row($query))
-
-
{ @unlink($row[4]);
-
@unlink($row[5]);
-
}
-
-
if (mysql_query("delete from news where no='$no'")) echo "news deleted";
-
else echo "not deleted";
-
-
}
-
?>
-
<?
-
if ($_POST[edit])
-
{
-
-
$query=mysql_query("select * from news where no='$no'");
-
while($row=mysql_fetch_row($query))
-
{
-
$no2=$row[0];
-
$baslik2=$row[1];
-
$ozet2=$row[2];
-
$aciklama2=$row[3];
-
$kucukresim2=$row[4];
-
$resim2=$row[5];
-
$aktif2=$row[7];
-
}
-
}
-
?>
-
<? if($_POST["add"])
-
{ //echo "
-
if(strlen($_FILES["image"]["name"])>4)
-
{//
-
//
-
//
-
$find=$_FILES["image"] ;
-
$tobesearched = array('ç','Ç','ý','Ý','ð','Ð','ü','ö','Þ','þ','Ö','Ü',',',' ','(',')','[',']');
-
$change = array('c','C','i','I','g','G','u','o','S','s','O','U','','_','','','','');
-
-
$_FILES["image"]=str_replace($tobesearched, $change, $find);
-
-
$image = "$large_pic/".$_FILES["image"]["name"];
-
move_uploaded_file($_FILES["image"]["tmp_name"],$image);
-
-
$little_image = "$little_pic/".$_FILES["image"]["name"];
-
move_uploaded_file($_FILES["image"]["tmp_name"],$little_image);
-
-
-
// little image resampling
-
$prepare = resample($image,$little_pic_width,$little_pic_heigth);
-
$folder = fopen ($little_image,"w+");
-
fwrite($folder,$prepare);
-
fclose($folder);
-
-
// large image resampling
-
$prepare = resample($image,$large_pic_width,$large_pic_heigth);
-
$folder = fopen ($image,"w+");
-
fwrite($folder,$prepare);
-
fclose($folder);
-
-
// end of resampling
-
-
}
-
-
-
if (!$no)
-
{
-
-
if (mysql_query("insert into news values ('','$title','$subject','$description','$little_image','$image','$aktiv')"))
-
{echo " done"; $image="";$little_image="";}
-
else echo " not added";
-
-
}
-
else
-
{ //
-
if ($image) $imageadd=",image='$image',littleimage='$little_image'";
-
if (mysql_query("update news set title='$title',subject='$subject',description='$description',aktiv='$aktiv' $imageadd where no='$no'"))
-
{echo " done"; $image="";$little_image="";}
-
else echo " not added ";
-
}
-
}
-
?>
-
<hr />
-
-
<form id="form1" name="form1" method="post" action="">
-
c urrent news :
-
<label>
-
<select name="no" id="no">
-
<?
-
$query=mysql_query("select * from news order by no desc");
-
while($row=mysql_fetch_row($query))
-
{
-
echo "<option value='$row[0]'>$row[1]</option>";
-
}
-
?>
-
-
</select>
-
</label>
-
<label>
-
<input name="edit" type="submit" id="edit" value="edit" />
-
</label>
-
<label>
-
<input name="del" type="submit" id="del" value="del" />
-
</label>
-
<label></label>
-
</form>
-
<hr />
-
<form id="form2" name="form2" method="post" action="" enctype="multipart/form-data">
-
<table width="800" border="1" cellspacing="5" cellpadding="0">
-
<tr>
-
<td width="129">no
-
<input name="no" type="hidden" value="<? echo $no2; ?>" /></td>
-
<td width="650"><label></label> </td>
-
</tr>
-
<tr>
-
<td>image
-
<? if($little_image2)
-
-
{echo "<img src=$little_image2 align=right><br />";
-
//echo "<input name='kucukresim' type='hidden' id='kucukresim' value='$kucukresim2' />";
-
}
-
?>
-
</td>
-
<td> <label>
-
<input name="image" type="file" id="image" />
-
</label></td>
-
</tr>
-
<tr>
-
<td>title </td>
-
<td><input name="title" type="text" id="title" value="<? echo $title2;?>" size="100" /></td>
-
</tr>
-
<tr>
-
<td>subject</td>
-
<td><input name="subject" type="text" id="subject" value="<? echo $subject2;?>" size="100" /></td>
-
</tr>
-
<tr>
-
<td>description</td>
-
<td><label>
-
<textarea name="description" cols="80" rows="5" id="is"><? echo $description2;?></textarea>
-
</label></td>
-
</tr>
-
<tr>
-
<td>Aktiv</td>
-
<td><label>
-
<input <?php if ($aktiv2=="aktiv") {echo "checked=\"checked\"";} ?> name="aktiv" type="radio" value="aktiv" checked="checked" />
-
activate
-
<input <?php if ($aktiv2=="pasiv") {echo "checked=\"checked\"";} ?> name="aktiv" type="radio" value="pasiv" />
-
passivate</label></td>dffdg
-
</tr>
-
<tr>
-
<td> </td>
-
<td><input name="edit" type="submit" id="edit" value="edit" />
-
<label>
-
<input name="search" type="submit" id="search" value="search" />
-
<input name="show" type="submit" id="show" value="show all news" />
-
</label></td>
-
</tr>
-
</table>
-
</form>
-
-
<p> </p>
-
<?
-
if (($search) || ($show))
-
{
-
if ($search)
-
{
-
if ($title) $query=mysql_query("select * from news where title like '%$title%'");
-
if ($subject) $query=mysql_query("select * from news where subject like '%$subject%'");
-
if ($description) $query=mysql_query("select * from news where description like '%$description%'");
-
}
-
if ($show)
-
{
-
$query=mysql_query("select * from news order by no desc");
-
}
-
echo "<table border=1>
-
<tr>
-
<td>edit</td>
-
<td>del</td>
-
<td>No</td>
-
<td>baslik</td>
-
<td>subject</td>
-
<td>description</td>
-
<td>littleimage</td>
-
<td>aktiv</td>
-
</tr>";
-
while($row=mysql_fetch_row($query))
-
{echo "
-
<tr><form action=\"\" method=\"post\"><input name=\"no\" type=\"hidden\" value=\"$row[0]\">
-
-
<td><input name=\"edit\" type=\"submit\" value=\"edit\"> </td>
-
<td><input name=\"del\" type=\"submit\" value=\"del\"></td>
-
-
<td>$row[0] </td>
-
<td>$row[1] </td>
-
<td>$row[2] </td>
-
<td>$row[3] </td>
-
<td><img src=$row[4]> </td>
-
<td>$row[6]</td>
-
</form> </tr>";
-
}
-
echo "</table>";
-
}
-
?>
-
</body>
-
</html>
index.php
i will wait your responses
thanks for attention
Atli 5,058
Expert 4TB
That's hundred of lines of code! I just needed the part that was causing the problem, not the whole thing.
In your index.php file - around line #80 - you are printing the HTML that shows the list of articles, and their accompanying thumbnail images. In that part of your code, you simply need to make sure the image file exists (see the link I posted earlier) before you print it. If it doesn't exist, replace it with a place-holder or simply remove the <img> tag.
thank you
but exactly i dont know it is dependent on haber_ekle.php or index.php
because i did so much thinks in index.php
but i got nothink
if it is index.php can you show where to paste the code
code that you said
thank you for attention
Atli 5,058
Expert 4TB @azegurb
Index.php, lines #71 through #84. - This is where your HTML for the article headlines is being printed. This is what you need to change to replace/remove the thumbs that are broken.
The query fetches the article data from the database - and ignoring for now the fact that you are putting invalid links into the database in the first place - you need to simply verify that the image is valid before printing the <img> tag.
It's not all that complex. You just use the file_exists function on the image location and print the appropriate HTML based on what it returns.
Try it. Post your attempts here. (Just the alterations please, we don't need another 400 lines of code!)
finally I did
Thank you very much
you helped me best
Let God loves you
Thanks Thanks Thanks
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Shelly |
last post by:
This is driving me crazy and makes no sense. Any suggestions will be
appreciated.
I upload an image to a staging area. I have written software to look at the
images, and if accepted it is...
|
by: Akbar |
last post by:
Hey there,
Big-time curiosity issue here...
Here's the test code (it's not that long)... it's to display a large
number of image links with captions, ideally pulled in from an
external file...
|
by: Tim::.. |
last post by:
Can someone please help....
I'm having major issues with a user control I'm tring to create!
I an trying to execute a sub called UploadData() from a user control which I
managed to do but for...
|
by: Silvia |
last post by:
Hi,
I have a program that capture images and put this into a listview (using imagelist), the problem is when I delete de image
the listview, when do that and capture another image, the image...
|
by: peterf |
last post by:
Posted in alt.comp.lang.php before I saw how much more active this group
is... Hope someone can help.
I am new to this group and needing a little bit of guidance. First off I
need to say that...
|
by: danxavier |
last post by:
I successfuly installed dd.php and sajax.php files. It runs fine, but I would like to link the $items to an image. I called the field in mysql with the link "pic". Any help would be AWESOME!!! I've...
|
by: Christian Schlemmer |
last post by:
hi,
in a DetailsView i have a image display.
images i want to store in a seperate directory, but it a path is added to
Bind update and delete is not working.
just Bind makes my...
|
by: Hexman |
last post by:
Hello All,
I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm
using some VB6 code, .Net2003 code,...
|
by: Poppa Pimp |
last post by:
ImageResizer.php
Image Resizer PLEASE HELP
The URL of the page this is on in my site is http://poppa-pimps-wallpapers.com//ImageResizer.php You can click on browse and get image,but...
|
by: gunimpi |
last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431
********************************************************
VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
wanted...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |