title: file_get_contents in wordpress function
body: <p>This code works correctly and saves a remote image to localhost (this wordpress plugin save tmdb cast image to local address):</p>
  
  <pre><code>function dt_cast_2($id, $type, $limit = false)
  {
      $name = get_post_meta($id, "dt_cast", $single = true);
      if ($type == "img") {
          if ($limit) {
              $val    = explode("]", $name);
              $passer = $newvalor = array();
              foreach ($val as $valor) {
                  if (!empty($valor)) {
                      $passer[] = substr($valor, 1);
                  }
              }
              for ($h = 0; $h &lt;= 500; $h++) {
                  $newval     = explode(";", $passer[$h]);
                  $fotoor     = $newval[0];
                  $actorpapel = explode(",", $newval[1]);
                  if (!empty($actorpapel[0])) {
  
                      if ($newval[0] == "null") {
                          $fotoor = DT_DIR_URI . '/assets/img/no_foto_cast.png';
                      } else {                   
                      $fotoor = 'https://image.tmdb.org/t/p/w90' . $newval[0];
                      $uploaddir = wp_upload_dir();
                      $uploadfile = $uploaddir['basedir'] . $newval[0];
                      if(!file_exists($uploadfile))
                      {
                      $contents= file_get_contents($fotoor);
                      $savefile = fopen($uploadfile, 'w');
                      fwrite($savefile, $contents);
                      fclose($savefile);
                      }
                      $fotoor = $uploaddir['baseurl'] . $newval[0];
                      }}}}}}
  </code></pre>
  
  <p>I have a problem in this function, the image is not saved to local.
  Can someone give me the correct code?</p>
  
  <pre><code>function dt_image($name, $id, $size, $type = false, $return = false, $gtsml = false) {
      $img    = get_post_meta($id, $name, $single = true);
      $val    = explode("\n", $img);
      $mgsl = array();
      $count  = 0;
      foreach ($val as $valor) {
          if (!empty($valor)) {
              if (substr($valor, 0, 1) == "/") {
                  $mgsl[] = 'https://image.tmdb.org/t/p/' . $size . '' . $valor . '';
              } else {
                  $mgsl[] = $valor;
              }
              $count++;
          } else {
              if ($name == "dt_poster" &amp;&amp; $img == NULL) {
                  $mgsl[] = esc_url( DT_DIR_URI ) . '/assets/img/no_poster.png';
              }
          }
      }
  </code></pre>