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.
Not a member yet? Click here to register.
Forgot Password?

Adding an avatar to the article

Asked Modified Viewed 1,753 times
K
Kot
K
Kot 10
  • Junior Member, joined since
  • Contributed 32 posts on the community forums.
  • Started 11 threads in the forums
  • Started this discussions
asked
Junior Member

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
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
   if (isset($_POST['save'])) {

replaced news_image by article_image and added to dbquery UPDATE command article_image='$article_obrazek_t2'
Added code:
      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?
Edited by Kot on 29-09-2013 21:08,
0 replies
There are no post found.

Labels

None yet

Statistics

  • Views 0 views
  • Posts 0 posts
  • Votes 0 votes
  • Topic users 1 member

1 participant

K
K
Kot 10
  • Junior Member, joined since
  • Contributed 32 posts on the community forums.
  • Started 11 threads in the forums
  • Started this discussions

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet