PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, May 16, 2022

[FIXED] How to save all generated unique names of downloaded photos to the MySQL database in Redbean PHP?

 May 16, 2022     file, mysql, php, redbean     No comments   

Issue

How to save all generated unique names of downloaded photos to the MySQL database in Redbean PHP

Just started learning the Redbean PHP library.

Here is my code.

I can not understand how to do it, I studied the Redbean documentation but failed to find the necessary one.

    require_once"Rb.php";
     require_once"Db.php";

 $data = $_POST;
 $photo = $_FILES;
    
    if(isset($data['submit']))       { 
     

      /* Uploads Folder */
      

           $uploads_dir = '../Images';
      
      
      $source = $uploads_dir;
      
foreach ($photo["file"]["error"] as $key => $error) {
  
    if ($error == UPLOAD_ERR_OK) {
      
       $original_name = $photo["file"]["name"][$key];

      
         $tmp_name = $photo["file"]["tmp_name"][$key];
      
      
           $size = $photo["file"]["size"][$key];
  
      
    // Get extension 
     
      
         $ext = pathinfo($original_name, PATHINFO_EXTENSION);
     
 
      
      /* New names */

      
          $token = random_bytes(7);   
       
     $p = '.'; 
      
          $name =  bin2hex(microtime() . $token) . ($photo["file"][$key])  . $p . $ext;
    
      
      /* Upload Photos  */
      
           
                    move_uploaded_file($tmp_name, "$uploads_dir/$name");         
}


  /*Show DATA */ 
  
   echo'<pre>';
      print_r($data);
   echo'</pre>';
  
      
       echo'<pre>';
         print_r($photo);
       echo'</pre>';  
  } 
}

Solution

For anyone who uses RedBean PHP, never name tables with capital letters or underscores, this will throw an error. I renamed the table and everything worked out.

// Upload Photos 
if(move_uploaded_file($tmp_name, "$uploads_dir/$name"))   {
    // SAVE names of photos
    $image = R::dispense('photorent');
    $image->photo = $name;
    R::store($image);
    echo "Success";
}


Answered By - Eric7777777
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing