Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.

Adding an avatar to the article

I'd like to have something like that there is in the news - a button "add image" that adds an avatar to the article. I added field article_image to the database, line
CodeDownload  
echo "<td class='tbl'><input type='file' name='article_image' class='textbox' style='width:250px;' /></td>\n";


to the file articles.php in the administration folder, then copied a piece of code from news.php and pasted it into articles.php just under the line 44
CodeDownload  
   if (isset($_POST['save'])) {


replaced news_image by article_image and added to dbquery UPDATE command article_image='$article_obrazek_t2'
Added code:
CodeDownload  
      if (isset($_FILES['article_image']) && is_uploaded_file($_FILES['article_image']['tmp_name'])) {
      require_once INCLUDES."photo_functions_include.php";

      $image = $_FILES['article_image'];
      $image_name = stripfilename(str_replace(" ", "_", strtolower(substr($image['name'], 0, strrpos($image['name'], ".")))));
      $image_ext = strtolower(strrchr($image['name'],"."));

      if ($image_ext == ".gif") { $filetype = 1;
      } elseif ($image_ext == ".jpg") { $filetype = 2;
      } elseif ($image_ext == ".png") { $filetype = 3;
      } else { $filetype = false; }

      if (!preg_match("/^[-0-9A-Z_\.\[\]]+$/i", $image_name)) {
         $error = 1;
      } elseif ($image['size'] > $settings['article_photo_max_b']){
         $error = 2;
      } elseif (!$filetype) {
         $error = 3;
      } else {
         $image_t1 = image_exists(IMAGES_N_T, $image_name."_t1".$image_ext);
         $image_t2 = image_exists(IMAGES_N_T, $image_name."_t2".$image_ext);
         $image_full = image_exists(IMAGES_N, $image_name.$image_ext);

         move_uploaded_file($_FILES['article_obrazek']['tmp_name'], IMAGES_N.$image_full);
         if (function_exists("chmod")) { chmod(IMAGES_N.$image_full, 0644); }
         $imagefile = @getimagesize(IMAGES_N.$image_full);
         
         if ($imagefile[0] > 1800 || $imagefile[1] > 1600) {
            $error = 4;
            unlink(IMAGES_N.$image_full);
         } else {
         
            createthumbnail($filetype, IMAGES_N.$image_full, IMAGES_N_T.$image_t1, 120, 120);
            
               createthumbnail($filetype, IMAGES_N.$image_full, IMAGES_N_T.$image_t2, 250, 250);
            
         }
      }
      if (!$error) {
         $article_image = $image_full;
         $article_image_t1 = $image_t1;
         $article_image_t2 = $image_t2;
      } else {
         $article_image = "";
         $article_image_t1 = "";
         $article_image_t2 = "";
      }
   } else {
      $article_image = (isset($_POST['article_image']) ? (preg_match("/^[-0-9A-Z_\.\[\]]+$/i", $_POST['article_image']) ? $_POST['article_image'] : "") : "");
      $article_image_t1 = (isset($_POST['article_image_t1']) ? (preg_match("/^[-0-9A-Z_\.\[\]]+$/i", $_POST['article_image_t1']) ? $_POST['article_image_t1'] : "") : "");
      $article_image_t2 = (isset($_POST['article_image_t2']) ? (preg_match("/^[-0-9A-Z_\.\[\]]+$/i", $_POST['article_image_t2']) ? $_POST['article_image_t2'] : "") : "");
   }


Adding articles works as it used to work, clicking on "Add image" opens the window for adding file, but no filename is added to the database nor is anything sent to the server. I don't know programming in php and here I reached my limit. Any help?

Merged on Sep 29 2013 at 21:08:21:
Is it really THAT hard?
Thread Information
Author
Replies
1 post
Views
1437 times
Last Post
Last updated on 7 years ago
You can view all discussion threads in this forum.
You cannot set up a bounty in this discussion thread.
You can start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
You cannot up or down-vote on the post in this discussion thread.
Users who participated in discussion: Kot