473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

help with news script with image upload feature (limage not displays when not added)

32
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
Attached Files
File Type: zip xeber_turk.zip (57.5 KB, 132 views)
Feb 23 '10 #1

✓ answered by Atli

@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)
Feb 23 '10 #2
azegurb
32
ok
i will translate it
Feb 23 '10 #3
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.
Feb 23 '10 #4
azegurb
32
image_add.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   function resample($image,$max_width,$max_height) 
  3.      { 
  4.  
  5.      # Icerik icin kesi baslat ... 
  6.      ob_start(); 
  7.  
  8.      # Ilk heightutlar 
  9.      $boyuut = getimagesize($image); 
  10.      $width    = $boyut[0]; 
  11.      $height   = $boyut[1]; 
  12.  
  13.      # new heightutlar 
  14.      $x_oran = $max_width  / $width; 
  15.      $y_oran = $max_height / $height; 
  16.  
  17.      if (($width <= $max_width) and ($height <= $max_height)){ 
  18.         $son_width  = $width; 
  19.         $son_height = $height; 
  20.         } 
  21.      else if (($x_oran * $height) < $max_height){ 
  22.         $son_width  = $max_width; 
  23.         $son_height = ceil($x_oran * $height); 
  24.         } 
  25.      else { 
  26.         $son_width  = ceil($y_oran * $width); 
  27.         $son_height = $max_height; 
  28.         } 
  29.  
  30.      # old ve new imageler 
  31.      $old = imagecreatefromjpeg($image); 
  32.      $new = imagecreatetruecolor($son_width,$son_height); 
  33.  
  34.      # old image
  35.      imagecopyresampled( 
  36.         $new,$old,0,0,0,0, 
  37.         $son_width,$son_height,$width,$height); 
  38.  
  39.      # new image
  40.      imagejpeg($new,null,-1); 
  41.      $icerik = ob_get_contwidthts(); 
  42.  
  43.  
  44.      ob_widthd_clean(); 
  45.      imagedestroy($old); 
  46.      imagedestroy($new); 
  47.  
  48.      return $icerik; 
  49.  
  50.  }
  51. ?>
add_news.php
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9" />
  5. <title>Dahi Tasarim</title>
  6. <script type="text/JavaScript">
  7. <!--
  8. function MM_jumpMenu(targ,selObj,restore){ //v3.0
  9.   eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  10.   if (restore) selObj.selectedIndex=0;
  11. }
  12. //-->
  13. </script>
  14. </head>
  15.  
  16. <body>
  17. <p>
  18. <? 
  19. include("connect.php"); 
  20. //include ("oturum_kontrol.php");    
  21. //include ("yonetim_menu.php");
  22. include ("image_add.php"); 
  23. ?>
  24.  
  25. </p>
  26. <p style="font-size:24pt; color:#FF0000;">Haber Ekle </p>
  27.  
  28. <hr />
  29. News :&nbsp;
  30. <? /
  31.  
  32. $no=$_POST[no];
  33. $title=$_POST[title];
  34. $subject=$_POST[subject];
  35. $description=$_POST[description];
  36. $aktiv=$_POST[aktiv];
  37. $search=$_POST[search];
  38. $show=$_POST[show];
  39.  
  40. // image settings
  41.     $little_pic="little_pictures"; // open this directory
  42.     $large_pic="large_pictures"; // and give permission chmod 777
  43.  
  44.     $large_pic_width=640;
  45.     $large_pic_heigth=480;
  46.  
  47.     $little_pic_width=200;
  48.     $little_pic_heigth=150;
  49.  
  50.  
  51.  
  52. //if ($image)
  53.  
  54. ?>
  55. <?  if ($_POST[del])
  56. {// if pressed del button
  57. $query=mysql_query("select * from news where no='$no'");
  58. while($row=mysql_fetch_row($query))
  59.  
  60.     { @unlink($row[4]);
  61.         @unlink($row[5]); 
  62.     }
  63.  
  64. if (mysql_query("delete from news where no='$no'")) echo "news deleted";
  65. else echo "not deleted";
  66.  
  67. }
  68. ?>
  69. <? 
  70. if ($_POST[edit])
  71. {
  72.  
  73. $query=mysql_query("select * from news where no='$no'");
  74.     while($row=mysql_fetch_row($query))
  75.     { 
  76.     $no2=$row[0];
  77.     $baslik2=$row[1];
  78.     $ozet2=$row[2];
  79.     $aciklama2=$row[3];
  80.     $kucukresim2=$row[4];
  81.     $resim2=$row[5];
  82.     $aktif2=$row[7];
  83.     }
  84. }
  85. ?>
  86. <? if($_POST["add"])
  87. { //echo "
  88. if(strlen($_FILES["image"]["name"])>4)
  89.         {// 
  90.          // 
  91.          // 
  92.         $find=$_FILES["image"] ;
  93.         $tobesearched = array('ç','Ç','ý','Ý','ð','Ð','ü','ö','Þ','þ','Ö','Ü',',',' ','(',')','[',']'); 
  94.         $change  = array('c','C','i','I','g','G','u','o','S','s','O','U','','_','','','',''); 
  95.  
  96.         $_FILES["image"]=str_replace($tobesearched, $change, $find);
  97.  
  98.         $image = "$large_pic/".$_FILES["image"]["name"];        
  99.         move_uploaded_file($_FILES["image"]["tmp_name"],$image);
  100.  
  101.         $little_image  = "$little_pic/".$_FILES["image"]["name"];  
  102.         move_uploaded_file($_FILES["image"]["tmp_name"],$little_image);
  103.  
  104.  
  105.         // little image resampling
  106.         $prepare = resample($image,$little_pic_width,$little_pic_heigth); 
  107.         $folder  = fopen ($little_image,"w+"); 
  108.                    fwrite($folder,$prepare); 
  109.                    fclose($folder); 
  110.  
  111.         // large image resampling
  112.         $prepare = resample($image,$large_pic_width,$large_pic_heigth); 
  113.         $folder  = fopen ($image,"w+"); 
  114.                    fwrite($folder,$prepare); 
  115.                    fclose($folder); 
  116.  
  117.         // end of resampling
  118.  
  119.         }
  120.  
  121.  
  122. if (!$no)
  123.     {
  124.  
  125.     if (mysql_query("insert into news values ('','$title','$subject','$description','$little_image','$image','$aktiv')"))
  126.     {echo " done"; $image="";$little_image="";}
  127.     else echo " not added";
  128.  
  129.     }
  130. else 
  131. { // 
  132.     if ($image) $imageadd=",image='$image',littleimage='$little_image'";
  133.     if (mysql_query("update  news set title='$title',subject='$subject',description='$description',aktiv='$aktiv' $imageadd where no='$no'"))
  134.     {echo " done"; $image="";$little_image="";}
  135.     else echo " not added ";
  136.     }
  137. }
  138. ?>
  139. <hr />
  140.  
  141. <form id="form1" name="form1" method="post" action="">
  142.  c urrent news :
  143.   <label>
  144.   <select name="no" id="no">
  145.   <?
  146.   $query=mysql_query("select * from news order by no desc");
  147. while($row=mysql_fetch_row($query))
  148. {
  149. echo "<option value='$row[0]'>$row[1]</option>";
  150. }
  151.   ?>
  152.  
  153.   </select>
  154.   </label>
  155.   <label>
  156.   <input name="edit" type="submit" id="edit" value="edit" />
  157.   </label>
  158.   <label>
  159.   <input name="del" type="submit" id="del"  value="del" />
  160.   </label>
  161.   <label></label>
  162. </form>
  163. <hr />
  164. <form id="form2" name="form2" method="post" action=""   enctype="multipart/form-data">
  165.   <table width="800" border="1" cellspacing="5" cellpadding="0">
  166.     <tr>
  167.       <td width="129">no 
  168.       <input name="no" type="hidden" value="<? echo $no2; ?>" /></td>
  169.       <td width="650"><label></label>      </td>
  170.     </tr>
  171.     <tr>
  172.       <td>image
  173.  <? if($little_image2)
  174.  
  175. {echo "<img src=$little_image2 align=right><br />";
  176. //echo "<input name='kucukresim' type='hidden' id='kucukresim' value='$kucukresim2' />";
  177. }
  178. ?>
  179. </td>
  180.       <td>   <label>
  181.       <input name="image" type="file" id="image" />
  182.       </label></td>
  183.     </tr>
  184.     <tr>
  185.       <td>title </td>
  186.       <td><input name="title" type="text" id="title" value="<? echo $title2;?>" size="100" /></td>
  187.     </tr>
  188.     <tr>
  189.       <td>subject</td>
  190.       <td><input name="subject" type="text" id="subject" value="<? echo $subject2;?>" size="100" /></td>
  191.     </tr>
  192.     <tr>
  193.       <td>description</td>
  194.       <td><label>
  195.         <textarea name="description" cols="80" rows="5" id="is"><? echo $description2;?></textarea>
  196.       </label></td>
  197.     </tr>
  198.     <tr>
  199.       <td>Aktiv</td>
  200.       <td><label>
  201.         <input <?php if ($aktiv2=="aktiv") {echo "checked=\"checked\"";} ?>  name="aktiv" type="radio" value="aktiv" checked="checked" />
  202.      activate
  203.       <input <?php if ($aktiv2=="pasiv") {echo "checked=\"checked\"";} ?>  name="aktiv" type="radio" value="pasiv" />
  204.       passivate</label></td>dffdg
  205.     </tr>
  206.     <tr>
  207.       <td>&nbsp;</td>
  208.       <td><input name="edit" type="submit" id="edit" value="edit" />
  209.         <label>
  210.         <input name="search" type="submit" id="search" value="search" />
  211.         <input name="show" type="submit" id="show" value="show all news" />
  212.         </label></td>
  213.     </tr>
  214.   </table>
  215. </form>
  216.  
  217. <p>&nbsp;</p>
  218. <? 
  219. if (($search) || ($show))
  220. {
  221. if ($search)
  222. {
  223. if ($title) $query=mysql_query("select * from news where title like '%$title%'");
  224. if ($subject) $query=mysql_query("select * from news where subject like '%$subject%'");
  225. if ($description) $query=mysql_query("select * from news where description like '%$description%'");
  226. }
  227.  if ($show)
  228. {
  229. $query=mysql_query("select * from news order by no desc");
  230. }
  231. echo "<table border=1>
  232. <tr>
  233. <td>edit</td>
  234. <td>del</td>
  235. <td>No</td>
  236. <td>baslik</td>
  237. <td>subject</td>
  238. <td>description</td>
  239. <td>littleimage</td>
  240. <td>aktiv</td>
  241. </tr>";
  242. while($row=mysql_fetch_row($query))
  243. {echo "
  244. <tr><form action=\"\" method=\"post\"><input name=\"no\" type=\"hidden\" value=\"$row[0]\">
  245.  
  246. <td><input name=\"edit\" type=\"submit\" value=\"edit\">    </td>
  247. <td><input name=\"del\" type=\"submit\" value=\"del\"></td>
  248.  
  249. <td>$row[0]&nbsp;</td>
  250. <td>$row[1]&nbsp;</td>
  251. <td>$row[2]&nbsp;</td>
  252. <td>$row[3]&nbsp;</td>
  253. <td><img src=$row[4]>&nbsp;</td>
  254. <td>$row[6]</td>
  255. </form>    </tr>";
  256. }
  257. echo "</table>";
  258. }
  259. ?>
  260. </body>
  261. </html>
index.php

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9" />
  5. <title>Dahi Tasarim . CoM</title>
  6. <style type="text/css">
  7. <!--
  8. a:link {
  9.     color: #0066FF;
  10.     text-decoration: underline;
  11. }
  12. a:visited {
  13.     text-decoration: underline;
  14.     color: #0033CC;
  15. }
  16. a:hover {
  17.     text-decoration: none;
  18.     color: #FFFFFF;
  19. }
  20. a:active {
  21.     text-decoration: underline;
  22. }
  23. -->
  24. </style></head>
  25.  
  26. <body>
  27.  
  28. <? // baglan php yi yukluyoruz
  29. include("connect.php"); 
  30. // bu satýrda adres satýrýndan (GET metodu) no bilgisi gelmiþmi diye kontrol ediyoruz...
  31. $no=$_GET["no"];
  32. //eger $no yoksa demekki talep edilen bir newsin devami yok
  33. //biz en son kaydi veritabanýndan cekiyoruz 
  34. if (!$no)
  35. {$query=mysql_query("select * from news where aktiv='aktiv' order by no desc limit 1");
  36. }
  37. else // eger $no varsa istenilen nolu newsi veritabanýndan cekiyoruz
  38. {$query=mysql_query("select * from news where no='$no'");
  39. }
  40. while($satir=mysql_fetch_row($query))
  41. {
  42. $baslik=$satir[1];
  43. $ozet=$satir[2];
  44. $metin=$satir[3];
  45. $kucukresim=$satir[4];
  46. $buyukresim=$satir[5];
  47. $metin=str_replace ("\n","<br />",$metin);
  48. // \n br ile admin sayfasýnda aciklama kismina girdigimiz enterlari
  49. // br ye cevirip alt satir yapiyoruz
  50. }
  51. ?>
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. <table border="1" cellpadding="10" cellspacing="10" bordercolor="#666666" bgcolor="#CCCCCC">
  59.   <tr>
  60.     <td width="640" valign="top" bgcolor="#FFCC00"><img alt="" src="<?=$buyukresim; ?>" />
  61.                               <div class="indent1">
  62.                                   <h1><?=$baslik; ?> <span></span></h1>
  63.     <p><?=$metin; ?></p></td>
  64.     <td width="200" valign="top" bgcolor="#FF9900">
  65.  
  66. <? 
  67.  
  68. $query=mysql_query("select * from news where aktiv='aktiv' order by no desc limit 4");
  69. // en son 4 newsi veritabanindan cekiyoruz
  70. // baslik, kucuk resimleri ve ozetlerini ekrana basacagiz
  71. while($satir=mysql_fetch_row($query))
  72. {
  73. $no=$satir[0];
  74. $baslik=$satir[1];
  75. $ozet=$satir[2];
  76. $metin=$satir[3];
  77. $kucukresim=$satir[4];
  78. $buyukresim=$satir[5];
  79. echo "
  80. <p><a href='index.php?no=$no'>
  81. <img alt='' src='$kucukresim' /><br><span>$baslik</span></a><br />$ozet
  82. </p>";
  83. // index.php?no=$no ile istenilen newse link olusturuyoruz
  84. }
  85. ?></td>
  86.   </tr>
  87.   <tr>
  88.     <td colspan="2" bgcolor="#669933"><ul>
  89.  
  90.         <?
  91. $query=mysql_query("select * from news where aktiv='aktiv' order by no desc limit 0,20");
  92. // newslerin sadece basliklarini ekranda gosterip link verecegiz
  93. while($satir=mysql_fetch_row($query))
  94. {
  95. $no=$satir[0];
  96. $baslik=$satir[1];
  97. echo "<li> <a href=index.php?no=$no>$baslik</a></li>";
  98. }
  99. ?>
  100.  
  101.     </ul></td>
  102.   </tr>
  103. </table>
  104. <? 
  105. if ($query) mysql_free_result($query);
  106. if ($connect) mysql_close($connect); 
  107. ?>
  108. </body>
  109. </html>
i will wait your responses
thanks for attention
Feb 23 '10 #5
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.
Feb 23 '10 #6
azegurb
32
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
Feb 23 '10 #7
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!)
Feb 23 '10 #8
azegurb
32
finally I did
Thank you very much
you helped me best
Let God loves you
Thanks Thanks Thanks
Feb 23 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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...
14
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...
3
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...
0
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...
3
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...
1
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...
0
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...
53
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,...
2
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
jinu1996
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...
0
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...
0
tracyyun
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.