Uploading multiple images to imgur at once

Viewed 13

However I need to upload multiple images at once. On the client side, the user will have multiple fields. I'm completely stuck now with figuring out where and how I will need to modify this code in order to handle multiple image upload when they come through to the server in the form of an array. Does anyone have any ideas?

 <!DOCTYPE html>
<html>
 <body>
   <form action="index.php" enctype="multipart/form-data" method="POST">
    <input name="img" size="35" type="file" multiple/><br/>
    <input name="nick" type="hidden" value="zJakie"/><br/>
    <input type="submit" name="submit" value="Upload"/>
   </form>
   <?
   include '../reg/config.php';
   if(isset($_POST['submit'])){
    $img=$_FILES['img'];
    if($img['name']==''){
     echo "<h2>An Image Please.</h2>";
    }else{
     $filename = $img['tmp_name'];
     foreach ($img as $curl) {
     $client_id="000000000";
     $handle = fopen($filename, "r");
     $data = fread($handle, filesize($filename));
     $pvars   = array('image' => base64_encode($data));
     $timeout = 30;
     $curl    = curl_init();
     curl_setopt($curl, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
     curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
     curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id));
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
     $out = curl_exec($curl);
     curl_close ($curl);
     $pms = json_decode($out,true);
     $url=$pms['data']['link'];
     if($url!=""){
      $nick = $_POST['nick'];
      $sqlNick = "SELECT * FROM forms WHERE nickname='$nick' LIMIT 1";
      $resultNick = $conn->query($sqlNick);
      if ($resultNick->num_rows > 0) {
        while ($row = $resultNick->fetch_assoc()) {
                {
                    $id = $row['id'];
                    $sql5656 = "INSERT INTO forms_photos (forms_id, photo_link) VALUES ('$id', '$url')";
                    $result = $conn->query($sql5656);
                } 
        }
    }
  
     }else{
      echo "<h2>There's a Problem</h2>";
      echo $pms['data']['error']['message'];
     }
    }
   }
  }
   ?>
</html>
0 Answers
Related