首页 \ 问答 \ $ _FILES和cURL的问题(Problem with $_FILES and cURL)

$ _FILES和cURL的问题(Problem with $_FILES and cURL)

我在通过cURL发送$ _FILES时遇到了一些麻烦 - 使用以下代码将文件传输好了,但是我不可能获得文件的名称和类型,实际上一旦$ _FILES到达目的地他们的类型存储为“application / octet-stream” - 我做错了什么!?

 $count=count($_FILES['thefile']['tmp_name']);

 for($i=0;$i<$count;$i++) {
  if(!empty($_FILES['thefile']['name'][$i])) {
   $postargs[$i] = '@'.$_FILES['thefile']['tmp_name'][$i];
  }
 }


 $header = array("Content-type: multipart/form-data");
 $ch = curl_init('http://localhost/curl/rec.php');
 curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");  
 curl_setopt($ch,CURLOPT_RETURNTRANSFER, false); 
 curl_setopt($ch,CURLOPT_ENCODING,"");
 curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
 curl_setopt($ch,CURLOPT_FOLLOWLOCATION, TRUE);
 curl_setopt($ch,CURLOPT_POST,TRUE);
 curl_setopt($ch,CURLOPT_POSTFIELDS,$postargs);
 curl_exec($ch);
 curl_close($ch)

I'm having some trouble sending $_FILES by cURL - the files get transferred alright using the following code, however it is impossible for me to get the name, and type of the file, in fact once the $_FILES reach their destination their type is stored as "application/octet-stream" - what am I doing wrong!?

 $count=count($_FILES['thefile']['tmp_name']);

 for($i=0;$i<$count;$i++) {
  if(!empty($_FILES['thefile']['name'][$i])) {
   $postargs[$i] = '@'.$_FILES['thefile']['tmp_name'][$i];
  }
 }


 $header = array("Content-type: multipart/form-data");
 $ch = curl_init('http://localhost/curl/rec.php');
 curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");  
 curl_setopt($ch,CURLOPT_RETURNTRANSFER, false); 
 curl_setopt($ch,CURLOPT_ENCODING,"");
 curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
 curl_setopt($ch,CURLOPT_FOLLOWLOCATION, TRUE);
 curl_setopt($ch,CURLOPT_POST,TRUE);
 curl_setopt($ch,CURLOPT_POSTFIELDS,$postargs);
 curl_exec($ch);
 curl_close($ch)

原文:https://stackoverflow.com/questions/3223478
更新时间:2023-10-24 08:10

最满意答案

请对您的代码和脚本进行一些更改。我认为下面的代码可能对您有用。

<head><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {

$("#email").change(function() {

        var pass = $("#Repeat").val();
        var email = $("#email").val();
        if (pass === email) {
            $(".bar1").html("email match");
        }
else {
            $(".bar1").html("<span style='color:goldenrod;font-size: 11px;margin-left: 21px;font-family: Arial,Helvetica,sans-serif;'>email does not Match.</span>");
        }
    });
$("#Repeat").change(function() {
var pass = $("#Repeat").val();
        var email = $("#email").val();
        if (pass === email) {
            $(".bar2").html("email match");
             $(".bar1").hide();
        }
        else {
            $(".bar2").html("<span style='color:goldenrod;font-size: 11px;margin-left: 21px;font-family: Arial,Helvetica,sans-serif;'>email does not Match.</span>");

        }
    });

});
</script>
</head>

并在您的html部分进行一些更改,如更改类名和ID,如下所示。

<form>


<div class="input-container">
 <input type="text" id="Username" required="required"/>
<label for="Username">@Username</label>
<div class="bar"></div>
  </div>
<div class="input-container">
<input type="email" id="email" required="required"/>
<label for="email">Email</label>
<div class="bar1"></div>
</div>
<div class="input-container">
<input type="email" id="Repeat" required="required"/>
<label for="Repeat email">Repeat Email</label>
<div class="bar2"></div>
</div>
<div class="button-container">
<button><span>Next</span></button>
</div>
</form>

please make some changes in your code and script.I think below code may be useful to you.

<head><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {

$("#email").change(function() {

        var pass = $("#Repeat").val();
        var email = $("#email").val();
        if (pass === email) {
            $(".bar1").html("email match");
        }
else {
            $(".bar1").html("<span style='color:goldenrod;font-size: 11px;margin-left: 21px;font-family: Arial,Helvetica,sans-serif;'>email does not Match.</span>");
        }
    });
$("#Repeat").change(function() {
var pass = $("#Repeat").val();
        var email = $("#email").val();
        if (pass === email) {
            $(".bar2").html("email match");
             $(".bar1").hide();
        }
        else {
            $(".bar2").html("<span style='color:goldenrod;font-size: 11px;margin-left: 21px;font-family: Arial,Helvetica,sans-serif;'>email does not Match.</span>");

        }
    });

});
</script>
</head>

and make some changes in your html section like changing class name and id as below.

<form>


<div class="input-container">
 <input type="text" id="Username" required="required"/>
<label for="Username">@Username</label>
<div class="bar"></div>
  </div>
<div class="input-container">
<input type="email" id="email" required="required"/>
<label for="email">Email</label>
<div class="bar1"></div>
</div>
<div class="input-container">
<input type="email" id="Repeat" required="required"/>
<label for="Repeat email">Repeat Email</label>
<div class="bar2"></div>
</div>
<div class="button-container">
<button><span>Next</span></button>
</div>
</form>

相关问答

更多
  • 如果攻击者的YOURBESTGUESSHERE搜索空间足够大,暴力就变得不可行。 使用源自电子邮件地址的代码加上通过已知良好的单向散列函数实现的时间戳。 确保代码在使用后短时间内(也许是几天)才有效。 当代码呈现时不要泄露信息 - 代码的真实用户知道它适用于哪个电子邮件地址,并且没有其他人需要。 If the attacker's search space for YOURBESTGUESSHERE is large enough, brute force becomes infeasible. Use a ...
  • "verify.php?hash='.$hash.'"; 不正确,你不需要萎缩和点来将变量包含在双引号字符串中。 尝试 "verify.php?hash=$hash"; 然后做这样的mail($email, 'Please activate your account', "Hello " . $username. ",\r\nThank you for registering with us. Please visit the link below so we can activate your ac ...
  • 首先你不能用它来引用变量,因为它是在同一个函数内本地声明的。 尝试删除此关键字,或者选择性地执行电子邮件验证,如下所示: 注册后在你的功能里面: let user = firebase.auth().currentUser; user.sendEmailVerification(); this.navCtrl.setRoot('LoginPage'); First thing you cannot use this to reference the variable as it is declare ...
  • 请对您的代码和脚本进行一些更改。我认为下面的代码可能对您有用。