title: File transfer with PHP to another server returning "Internal Server Error"
body: <p>I'm experiencing some weird problem with PHP. I have a PHP script that performs a file upload to my sever and them, transfers it to a remote server. The code is correct as it works. The problem is that it does not ALLWAYS work. Most times, it just returns an Internal Server Error. My Error log just says that it has ocurred an error 404, but I don't do any "Header" commands. It just echoes some HTML and Javascript to an Iframe. And when the error occurs, the file is cut in the remote server, so I really can't figure out where the error is taking place. I guess it is some misconfiguration on my server, becouse I have tried the same script in MAMP and it worked perfectly, with no issues. Can anyone help me at least, to get the error it's throwing so that I know where to start?</p>
  
  <p>I know it's a bit simple, but i'm just not much experienced with PHP as I am with other languages.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>&lt;?php
  
  //Uploads a file
  
  $target_path = "uploadedMp3/";
  
  $target_path = $target_path . basename($_FILES['uploadedfile']['name']); 
  
  $returnMessage = '';
  
  if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
  {
      //FTP the file to VM Link
  
      $ftp_ip         = MY_IP;
      $ftp_username = MY_USER_NAME;
      $ftp_password = MY_PASSWORD;
  
      if($ftp=ftp_connect($ftp_ip,21,3600))
      {
          if(ftp_login($ftp,$ftp_username,$ftp_password))
          {
  
              // Set to PASV mode
  
              ftp_pasv( $ftp, 1);
  
  
              ftp_chdir($ftp,"/mp3/");
  
  
              // Send the file
  
              //set_time_limit(-1);       // PHP won't timeout
              //ignore_user_abort(true);
              ini_set('upload_max_filesize', '50M'); 
              ini_set('post_max_size', '50M');  
  
              $upload = ftp_put($ftp, $_FILES['uploadedfile']['name'],$target_path ,  FTP_BINARY); 
  
  
              $returnMessage .= "0##The file has been uploaded";
  
          }
          else
          {
              $returnMessage .= "-1##Ocorreu um erro de conexão com o servidor remoto. Entre em contato com a Mobilevel para mais informações.(1)";
          }
          ftp_close($ftp);
  
      }
      else
      {
           $returnMessage .= "-1##Ocorreu um erro na conexão com o servidor remoto. Entre em contato com a Mobilevel para mais informações.(2)";
      }
  } 
  else
  {
      $returnMessage .= "-1##Ocorreu um erro no Upload, tente novamente. Se o problema persistir entre em contato com a Mobilevel.";
  }
  
  unlink($target_path);
  echo "&lt;html&gt;&lt;head&gt;";
  echo "&lt;scr";
  echo "ipt type=\"text/javascript\"&gt;parent.uploadCallback('" . $returnMessage . "');&lt;/scr";
  echo "ipt&gt;";
  echo "&lt;/head&gt;&lt;body&gt;";
  echo "&lt;/body&gt;&lt;/html&gt;";
  /*
  echo "&lt;scr";
  echo "ipt type=\"text/javascript\"&gt;parent.uploadCallback('" . $returnMessage . "');&lt;/scr";
  echo "ipt&gt;&lt;/html&gt;";
  */
  
  ?&gt;
  </code></pre>