Witam
Mam taki problemik z wstawianiem zdjęć do artykułów i bardzo byłbym wdzięczny za pomoc.
Do następujących skryptów które odpowiadają za wstawianie artykułów i zdjęć do bazy chciałbym dodać możliwość wstawiania grafik(jpg, png itp). Jednak nie wiem jak połączyć, tak aby w odpowiednim miejscu w tekście był obrazek.
Chodzi o to że przy pisaniu artykułu chce zaznaczyć że akurat w tym miejscu ma być obrazek, który załaduje z dysku.
  1. plik z formularzem
  2. <?php
  3. require_once 'cms_naglowek.php';
  4. require_once '../funkcje/cms_polacz.php';
  5. $title = '';
  6. $body = '';
  7. $article = '';
  8. $authorid = '';
  9. $adres= '';
  10. if (isset($_GET['a'])
  11. and $_GET['a'] == 'edit'
  12. and isset($_GET['article'])
  13. and $_GET['article']) {
  14. $sql = "SELECT tytul,body,autor_id, dzial FROM cms_artykul " .
  15.  "WHERE artykul_id=" . $_GET['article'];
  16. $result = mysql_query($sql, $polacz)
  17. or die('Nie potrafię pobrać danych artykułu: ' . mysql_error());
  18.  
  19. $row = mysql_fetch_array($result);
  20.  
  21. $title = $row['tytul'];
  22. $body = $row['body'];
  23. $article = $_GET['article'];
  24. $authorid = $row['autor_id'];
  25. $adres = $row['dzial'];
  26. }else
  27. {?>
  28.  
  29. <a href="cms_wybor_dzialu.php?a=2" target="ramka"> >> Wybor działu <<</a> <?php
  30. }
  31.  
  32.  ?>
  33.  
  34. <form method="post" action="cms_transakcja_artykulu.php">
  35. <fieldset>
  36. <legend>
  37. Napisz Ogłoszenie</legend>
  38.  
  39.  
  40. <br>
  41.  
  42.  
  43. Tytuł:<br>
  44. <input type="text" class="title" name="title" maxlength="255"
  45. value="<?php echo htmlspecialchars($title); ?>">
  46.  
  47. <br>
  48. Treść:<br>
  49. <textarea class="body" name="body" rows="14" cols="75"><?php
  50. echo htmlspecialchars($body); ?></textarea>
  51. <br>
  52.  
  53. <?php
  54.  
  55. echo '<input type="hidden" name="article" value="' .
  56.  $article . "">n";
  57.  
  58.  
  59. echo '<input type="hidden" name="adres" value="' .
  60.  $adres . "">n";
  61.  
  62. if ($article) {
  63. echo '<input type="submit" class="submit" name="action" ' .
  64.  "value="Zapisz zmiany">n";
  65. } else {
  66. echo '<input type="submit" class="submit" name="action" ' .
  67.  "value="Wyślij nowy artykuł">n";
  68. }
  69.  
  70. ?>
  71. Aby dodać foto kliknij <a href="dodaj_foto.php"> tutaj</a> 
  72. </form>
  73. </fieldset>
  74. </p>
  75. </form>
  76. </body>
  77. </html>
  78. <?php require_once 'footer.php'; ?>

plik wstawiający do bazy
  1. <?php
  2. require_once '../funkcje/cms_polacz.php';
  3. require_once 'http.php';
  4.  
  5. if (isset($_REQUEST['action'])) {
  6. switch ($_REQUEST['action']) {
  7. case 'Wyślij nowy artykuł':
  8. if (isset($_POST['title'])
  9. and isset($_POST['body'])
  10. and isset($_SESSION['admin_logged'])
  11. )
  12. {
  13. $sql = "INSERT INTO cms_artykul " .
  14.  "(dzial, tytul,body, autor_id, data_dodania) " .
  15.  "VALUES ('".$_SESSION['adres'] . 
  16.  "','" . $_POST['title'] . 
  17.  "','" . $_POST['body'] .
  18.  "'," . $_SESSION['user_id'] . ",'" .
  19.  date("Y-m-d H:i:s", time()) . "')";
  20.  
  21. mysql_query($sql, $polacz)
  22. or die('Nie mogę wysłać artykułu: ' . mysql_error());
  23. }else { redirect('a.php');}
  24.  
  25.  
  26. redirect('cms_podzial_artykulow.php');
  27. break;
  28.  
  29. case 'Edytuj':
  30. redirect('cms_napisz_ogloszenie.php?a=edit&article=' . $_POST['article']);
  31. break;
  32.  .
  33.  .
  34.  .
  35. ?>


[/b]Wczytanie obrazka
  1. <title>Umieść obrazek na naszej witrynie!</title>
  2. </head>
  3.  
  4. <form name="form1" method="post" action="check_image.php"
  5. enctype="multipart/form-data">
  6.  
  7. <table border="0" cellpadding="5">
  8. <tr>
  9. <td>Tytuł obrazka<br>
  10. <em>Przykład: Do mnie mówisz?</em></td>
  11. <td><input name="image_caption" type="text" id="item_caption" size="55"
  12. maxlength="255"></td>
  13. </tr>
  14. <tr>
  15. <td>Nazwa użytkownika</td>
  16. <td><input name="image_username" type="text" id="image_username" size="15"
  17. maxlength="255"></td>
  18. </tr>
  19. <td>Umieszczany obraz:</td>
  20. <td><input name="image_filename" type="file" id="image_filename"></td>
  21. </tr>
  22. <br>
  23. <em>Przyjmowane są obrazy w formatach: GIF, JPG/JPEG i PNG.</em>
  24. <p align="center"><input type="submit" name="Submit" value="Wyślij">
  25.  
  26. <input type="reset" name="Submit2" value="Wyczyść">
  27. </p>
  28. </form>
  29. </body>
  30. </html>

wyświetlanie obrazka (niestety nie tak jak bym chciał)[b]
  1. <?php
  2.  
  3. require_once('polacz.php');
  4.  
  5. // udostępnienie zmiennych
  6. $image_caption = $_POST['image_caption'];
  7. $image_username = $_POST['image_username'];
  8. $image_tempname = $_FILES['image_filename']['name'];
  9. $today = date("Y-m-d");
  10.  
  11. // umieszczenie obrazu i sprawdzenie jego formatu
  12. $ImageDir ="d:/PHP/Projekt/Foto";
  13.  
  14. //**WSTAW TEN WIERSZ
  15. $ImageThumb = $ImageDir . "thumbs/";
  16. //**KONIEC WSTAWIENIA
  17.  
  18. $ImageName = $ImageDir . $image_tempname;
  19.  
  20. if (move_uploaded_file($_FILES['image_filename']['tmp_name'], 
  21. $ImageName)) {
  22.  
  23. // pobranie informacji na temat umieszczonego obrazu
  24. list($width, $height, $type, $attr) = getimagesize($ImageName);
  25.  
  26. if ($type > 3) {
  27. echo "Przykro nam, ale przesłany obraz nie jest w formacie GIF, JPG lub " .
  28.  "PNG.<br>";
  29. echo "Kliknij przycisk 'Wstecz' w przeglądarce i spróbuj ponownie.";
  30. } else {
  31.  
  32. // obraz jest w poprawnym formacie, można kontynuować
  33.  
  34. // wstawienie informacji w tabeli images
  35.  
  36. $insert = "INSERT INTO images
  37. (image_caption, image_username, image_date)
  38. VALUES
  39. ('$image_caption', '$image_username', '$today')";
  40. $insertresults = mysql_query($insert)
  41. or die(mysql_error());
  42.  
  43. $lastpicid = mysql_insert_id();
  44.  
  45. $newfilename = $ImageDir . $lastpicid . ".jpg";
  46.  
  47. if ($type == 2) {
  48. rename($ImageName, $newfilename);
  49. } else {
  50. if ($type == 1) {
  51. $image_old = imagecreatefromgif($ImageName);
  52. } elseif ($type == 3) {
  53. $image_old = imagecreatefrompng($ImageName);
  54. }
  55.  
  56. // skonwertuj obraz do formatu JPG
  57. $image_jpg = imagecreatetruecolor($width, $height);
  58. imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, 
  59.  $width, $height, $width, $height);
  60. imagejpeg($image_jpg, $newfilename);
  61. imagedestroy($image_old);
  62. imagedestroy($image_jpg);
  63. }
  64.  
  65. //**WSTAW NASTĘPUJĄCE WIERSZE
  66.  
  67. $newthumbname = $ImageThumb . $lastpicid . ".jpg";
  68.  
  69. // pobierz wymiary miniaturki
  70. $thumb_width = $width * 0.10;
  71. $thumb_height = $height * 0.10;
  72.  
  73. // utwórz miniaturkę
  74. $largeimage = imagecreatefromjpeg($newfilename);
  75. $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
  76. imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0, 
  77. $thumb_width, $thumb_height, $width, $height);
  78. imagejpeg($thumb, $newthumbname);
  79. imagedestroy($largeimage);
  80. imagedestroy($thumb);
  81. //**KONIEC WSTAWIANYCH WIERSZY
  82.  
  83. $url = "location: showimage.php?id=" . $lastpicid;
  84. header($url);
  85. }
  86. }
  87. ?>



Bardzo proszę o pomoc