Advertisement
Guest User

probem_move_uploaded_file

a guest
Apr 21st, 2019
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.75 KB | None | 0 0
  1.  
  2. intodb_add_post_php
  3.  
  4.       <?php
  5.    
  6.                                                                                                                                            
  7.     include 'intodb_functions.php';
  8.    
  9.     include '../../db.php';
  10.      
  11.      ob_start();
  12.    
  13.      global $connection;
  14.      
  15.    
  16.      
  17.     if (isset($_POST['addPost_submit'])) {
  18.             $post_title = mysqli_real_escape_string($_POST['addPost_post_title']) ;
  19.             $post_author = mysqli_real_escape_string($_POST['addPost_post_author']) ;
  20.             $post_category = (int)mysqli_real_escape_string($_POST['addPost_post_category']) ;
  21.             $post_tags = mysqli_real_escape_string($_POST['addPost_post_tags']) ;
  22.               // $post_image = escape($_POST['addPost_post_image']) ;
  23.             $post_content = mysqli_real_escape_string($_POST['addPost_post_content']) ;
  24.             $post_date = date( "\D\a\y y,m,d" ). ' Time '. date("H:i:s") ; 
  25.             $post_views_counts = 13;
  26.             $post_likes = 14;
  27.             $post_user_id = 12;
  28.             $post_comment_counts = 15;
  29.             $post_status =  (int)mysqli_real_escape_string($_POST['addPost_post_status']);
  30.             $post_image = $_FILES['addPost_post_image'];
  31.             $post_image_name = $_FILES['addPost_post_image']['name'];
  32.             $post_image_tmp_name = $_FILES['addPost_post_image']['tmp_name'];
  33.             $post_image_error = $_FILES['addPost_post_image']['error'];
  34.             $post_image_type = $_FILES['addPost_post_image']['type'];
  35.             $post_image_size = $_FILES['addPost_post_image']['size'];
  36.    
  37.             $post_image_ext = explode('.', $post_image_name);
  38.             $post_image_actual_ext = strtolower(end($post_image_ext));
  39.    
  40.             $post_image_allowed = array('jpg','jpeg','png');
  41.    
  42.    
  43.             if (in_array($post_image_actual_ext, $post_image_allowed)) {
  44.                 if ($post_image_error === 0) {
  45.                     if ($post_image_size < 200000) {
  46.                         $post_image_new_name = uniqid('', true). "." .$post_image_actual_ext;
  47.    
  48.                     $post_image_destination = '../../uploads/';
  49.                         if (is_dir($post_image_destination) && is_writable($post_image_destination)) {
  50.        
  51.                         $post_image_destination = '../../uploads/'.$post_image_new_name;
  52.                         var_dump($post_image_destination);
  53.                         move_uploaded_file($post_image_new_name, $post_image_destination);
  54.                         echo "Inside move_uploaded_file section";
  55.    
  56.     } else {
  57.         echo 'Upload directory is not writable, or does not exist.';
  58.     }
  59.                     } else {
  60.             header('Location: ../admin_addPost.php?addPost_status=image_too_big');
  61.    
  62.                     }
  63.                 } else {
  64.    
  65.             header('Location: ../admin_addPost.php?addPost_status=failed');
  66.                 }
  67.             } else {
  68.             header('Location: ../admin_addPost.php?addPost_status=image_type_not_allowed');
  69.    
  70.             }
  71.    
  72.             $query = "
  73.    INSERT INTO posts
  74.    (post_category, post_title, post_author, post_date, post_image, post_content, post_tags, post_comment_counts, post_status, post_views_counts, post_likes, post_user_id)
  75.    VALUES($post_category, '$post_title', '$post_author', '$post_date', '$post_image_new_name', '$post_content', '$post_tags', $post_comment_counts, $post_status, $post_views_counts, $post_likes, $post_user_id)
  76.    ";
  77.    
  78.    
  79.    
  80.     $query =    mysqli_query($connection, $query);
  81.    
  82.      
  83.         if ($query) {
  84.        
  85.      mysqli_close($connection);
  86.         header('Location: ../admin_addPost.php?addPost_status=success');
  87.        
  88.     } else {
  89.         echo $query;
  90.         die( mysqli_error($connection));
  91.         mysqli_close($connection);
  92.         header('Location: ../admin_addPost.php?addPost_status=failed');
  93.    
  94.     }
  95.    
  96.      
  97.    
  98.    
  99.      
  100.    
  101.     }
  102.    
  103.  
  104.  
  105. html ( I am getting head, footer via include )
  106.  
  107.  
  108.            
  109.          <!-- body  -->
  110.          
  111.         <div class="columns is-12 section is-centered ">
  112.            
  113.             <div   class="box column is-9  has-background-white-ter ">
  114.         <div class=" column is-centered">
  115.             <div class="column has-text-centered is-12">
  116.                 <h4 class="title is-4">Add New Post</h4>
  117.             </div>
  118.        
  119.        
  120.         <?php
  121.         if (isset($_GET['addPost_status'])) {
  122.           $status = $_GET['addPost_status'];
  123.        
  124.           if ($status == 'success') {
  125.         ?>
  126.            
  127.               <p style="margin-bottom: 15px;" class="has-background-
  128.      success has-text-centered ">
  129.              <?php
  130.          
  131.                echo '<b class="has-text-white"> Post Has Been Added <b/>
  132.     &nbsp';
  133.                echo '<span class=""> <a href="admin_addPost.php">Add
  134.    Another <a/><span/> &nbsp';
  135.                echo '<span class=""> <a href="#">Viwe Post <a/><span/>';
  136.              
  137.              
  138.              ?>
  139.             </p>
  140.        
  141.             <?php
  142.        
  143.        
  144.           } else {
  145.             ?>
  146.              <p style="margin-bottom: 15px;" class="has-background-
  147.      danger has-text-centered ">
  148.              <?php
  149.          
  150.                echo '<b class="has-text-white"> Something Went Wrong,
  151.    Please Try Again <b/>';
  152.              
  153.              
  154.              ?>
  155.             </p>
  156.        
  157.             <?php
  158.           }
  159.         }
  160.        
  161.         ?>
  162.            
  163.        
  164.               <form action="intodb/intodb_add_post.php" method="post"
  165.                     enctype="multipart/form-data" class="">
  166.          
  167.         <div class="columns is-12 is-centered">
  168.        
  169.         <div   class="  has-background-white-ter column is-9  ">
  170.        
  171.              
  172.         <div class="field column">
  173.           <p class="control  ">
  174.             <label  class="label" for="addPost_post_title">Post
  175.     Title</label>
  176.             <input id="addPost_post_title" class="input" type="text"
  177.     placeholder="Post Tile" name="addPost_post_title" />
  178.          
  179.            
  180.           </p>
  181.         </div>
  182.        
  183.         <div class="field column">
  184.           <p class="control  ">
  185.             <label class="label" for="addPost_post_author">Post
  186.     Author</label>
  187.            <!--  <input   class="input" id="addPost_post_author"
  188.        disabled="disabled" type="text" placeholder="Author"  
  189.         value="whatever" name="addPost_post_author" />
  190.               -->
  191.        
  192.               <input   class="input" id="addPost_post_author"  
  193.      type="text" placeholder="Author"  value="whatever"
  194.        name="addPost_post_author" />
  195.            
  196.           </p>
  197.         </div>
  198.          
  199.        
  200.         <div class="field column">
  201.           <p class="control  ">
  202.             <label class="label" for="addPost_post_status">Post
  203.      Status</label>
  204.          
  205.        
  206.              <div style="margin-top: 10px" class="select ">
  207.           <select id="addPost_post_status" name="addPost_post_status">
  208.             <option value="0"> Draft</option>  
  209.             <option value="1"> Publish</option>
  210.                    
  211.           </select>
  212.         </div>
  213.            
  214.           </p>
  215.         </div>
  216.        
  217.         <div class="field column">
  218.           <p class="control  ">
  219.             <label class="label" for="addPost_post_category">Post
  220.     Category</label>
  221.          
  222.             <div style="margin-top: 10px" class="select ">
  223.           <select id="addPost_post_category"
  224.       name="addPost_post_category">
  225.             <option value="0">Uncategorized</option>
  226.             <option value="1"> option1</option>
  227.              <option value="2"> option2</option>            
  228.           </select>
  229.         </div>
  230.        
  231.           </p>
  232.         </div>
  233.        
  234.         <div class="field column">
  235.           <p class="control  ">
  236.             <label class="label" for="addPost_post_tags">Post
  237.       Tags</label>
  238.             <input   class="input" id="addPost_post_tags"   type="text"
  239.       placeholder="Post Tags"    name="addPost_post_tags" />
  240.            
  241.           </p>
  242.         </div>
  243.        
  244.        
  245.          
  246.        
  247.         <div class="file has-name is-fullwidth column">
  248.        
  249.             <label class="label" for="addPost_post_image">Post
  250.      image</label>
  251.           <label class="file-label">
  252.          
  253.          
  254.                 <input class="" type="file" id="addPost_post_image"
  255.       name="addPost_post_image">
  256.          
  257.        
  258.           </label>
  259.        
  260.         </div>
  261.        
  262.         <div class="contro column">
  263.        
  264.             <label class="label" for="addPost_post_content">Post
  265.       Content</label>
  266.           <textarea id="addPost_post_content"
  267.       name="addPost_post_content" class="textarea has-fixed-size"
  268.      placeholder="Your Post Content Here" rows="10"></textarea>
  269.         </div>
  270.        
  271.         <div class="control column" >
  272.             <input type="submit" name="addPost_submit" value="Create
  273.      Post" class="button is-info my_fucking_hover_right_arrow" />
  274.        
  275.         </div>
  276.        
  277.         </div>
  278.        
  279.        
  280.         </div>
  281.         </form>
  282.         </div>
  283.        
  284.         <!--  -->
  285.          
  286.         </div>
  287.        
  288.          
  289.            
  290.          
  291.        
  292.         </div>
  293.        
  294.          <!-- body -->
  295.  
  296.  
  297. Apache logs
  298.  
  299. Error.log
  300.  
  301. [Sun Apr 21 21:19:41.860228 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP   1. {main}() /var/www/html/my_cms/admin/intodb/intodb_add_post.php:0, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  302. [Sun Apr 21 21:19:41.860240 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP   2. mysqli_real_escape_string() /var/www/html/my_cms/admin/intodb/intodb_add_post.php:17, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  303. [Sun Apr 21 21:19:41.860345 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP Warning:  mysqli_real_escape_string() expects exactly 2 parameters, 1 given in /var/www/html/my_cms/admin/intodb/intodb_add_post.php on line 18, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  304. [Sun Apr 21 21:19:41.860360 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP Stack trace:, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  305. [Sun Apr 21 21:19:41.860387 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP   1. {main}() /var/www/html/my_cms/admin/intodb/intodb_add_post.php:0, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  306. [Sun Apr 21 21:19:41.860398 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP   2. mysqli_real_escape_string() /var/www/html/my_cms/admin/intodb/intodb_add_post.php:18, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  307. [Sun Apr 21 21:19:41.860484 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP Warning:  mysqli_real_escape_string() expects exactly 2 parameters, 1 given in /var/www/html/my_cms/admin/intodb/intodb_add_post.php on line 20, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  308. [Sun Apr 21 21:19:41.860497 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP Stack trace:, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  309. [Sun Apr 21 21:19:41.860506 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP   1. {main}() /var/www/html/my_cms/admin/intodb/intodb_add_post.php:0, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  310. [Sun Apr 21 21:19:41.860517 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP   2. mysqli_real_escape_string() /var/www/html/my_cms/admin/intodb/intodb_add_post.php:20, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  311. [Sun Apr 21 21:19:41.865455 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP Warning:  mysqli_real_escape_string() expects exactly 2 parameters, 1 given in /var/www/html/my_cms/admin/intodb/intodb_add_post.php on line 26, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  312. [Sun Apr 21 21:19:41.865493 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP Stack trace:, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  313. [Sun Apr 21 21:19:41.865509 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP   1. {main}() /var/www/html/my_cms/admin/intodb/intodb_add_post.php:0, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  314. [Sun Apr 21 21:19:41.865522 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP   2. mysqli_real_escape_string() /var/www/html/my_cms/admin/intodb/intodb_add_post.php:26, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  315. [Sun Apr 21 21:19:41.865783 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP Notice:  Undefined variable: post_image_new_name in /var/www/html/my_cms/admin/intodb/intodb_add_post.php on line 72, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  316. [Sun Apr 21 21:19:41.865801 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP Stack trace:, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  317. [Sun Apr 21 21:19:41.865815 2019] [php7:notice] [pid 6285] [client ::1:35682] PHP   1. {main}() /var/www/html/my_cms/admin/intodb/intodb_add_post.php:0, referer: http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success
  318.  
  319.  
  320.  
  321. access.log
  322.  
  323.  
  324.  
  325. ::1 - - [21/Apr/2019:20:55:33 +0500] "POST /my_cms/admin/intodb/intodb_add_post.php HTTP/1.1" 302 9391 "http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
  326. ::1 - - [21/Apr/2019:20:55:39 +0500] "GET /my_cms/admin/admin_addPost.php?addPost_status=success HTTP/1.1" 200 2243 "http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
  327. ::1 - - [21/Apr/2019:21:05:15 +0500] "GET /my_cms/admin/ HTTP/1.1" 200 892 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
  328. ::1 - - [21/Apr/2019:21:05:22 +0500] "GET /my_cms/ HTTP/1.1" 200 2637 "http://localhost/my_cms/admin/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
  329. ::1 - - [21/Apr/2019:21:05:22 +0500] "GET /my_cms/inc/css/style.css HTTP/1.1" 304 178 "http://localhost/my_cms/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
  330. ::1 - - [21/Apr/2019:21:19:18 +0500] "POST /my_cms/admin/intodb/intodb_add_post.php HTTP/1.1" 302 10151 "http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
  331. ::1 - - [21/Apr/2019:21:19:18 +0500] "GET /my_cms/admin/admin_addPost.php?addPost_status=success HTTP/1.1" 200 2244 "http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
  332. ::1 - - [21/Apr/2019:21:19:41 +0500] "POST /my_cms/admin/intodb/intodb_add_post.php HTTP/1.1" 302 10151 "http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
  333. ::1 - - [21/Apr/2019:21:19:42 +0500] "GET /my_cms/admin/admin_addPost.php?addPost_status=success HTTP/1.1" 200 2244 "http://localhost/my_cms/admin/admin_addPost.php?addPost_status=success" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
  334. ::1 - - [21/Apr/2019:21:20:33 +0500] "-" 408 0 "-" "-"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement