简体   繁体   English

无法将文件从一台服务器传输到另一台服务器

[英]Trouble transfering file from a server to another server

Hello guys i'm having trouble uploading a file from my server to my friends server using php. 大家好,我无法使用php将文件从服务器上传到我的朋友服务器。 At first i was getting a 26 error now i am getting this error: 起初我遇到了26错误,现在我得到了这个错误:

Error: Possible file upload attack: filename ''.Array ( ) 1

Below is my code 下面是我的代码

<?php
 $ch = curl_init();
chmod("grademegood.us/uploadedfiles/hello.txt", 0755);

  $post =array(
  'file' => '@' . realpath('./uploadedfiles/hello.txt')
 );

 curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
 curl_setopt($ch, CURLOPT_URL, "http://friendsdomain.com/upload.php");
 curl_setopt($ch, CURLOPT_POST,true);

 $data = curl_exec($ch);

 if (curl_errno($ch))
{
 print curl_errno($ch);
}
else
{
  curl_close($ch);
 }

 echo $data;

 ?>

This is the receiving side code: 这是接收方代码:

<?php
$uploads_dir = './phpbackend/';
if(is_uploaded_file($_FILES['userfile']['tmp_name'])) 
{
  echo  "File ".  $_FILES['userfile']['name']  ." uploaded successfully to
 $uploads_dir/$dest.\n";
 $dest=  $_FILES['userfile'] ['name'];
 move_uploaded_file ($_FILES['userfile'] ['tmp_name'], "$uploads_dir/$dest");
} 
 else 
  {
    echo "Possible file upload attack: ";
    echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
    print_r($_FILES);
  }
?>

Please I need some assistance. 请给我一些帮助。

When you're setting up your cURL request you're setting up the POST variables with this: 设置cURL请求时,您将使用以下方法设置POST变量:

  $post =array(
    'file' => '@' . realpath('./uploadedfiles/hello.txt')
    );

The array keys are the variable names sent in the $_POST data. 数组键是在$_POST数据中发送的变量名。

When you come to unpack the file on the receiving server you're looking for 当您要在接收服务器上解压缩文件时

is_uploaded_file($_FILES['userfile']['tmp_name']

where 'userfile' should be the variable name used in the POST request sent by the sending machine. 其中'userfile'应该是发送计算机发送的POST请求中使用的变量名。

The variables created in the POST data must match the variable names used by the receiving machine or the two machines won't be able to identify the different fields correctly. 在POST数据中创建的变量必须与接收计算机使用的变量名称匹配,否则两台计算机将无法正确识别不同的字段。

At present you're creating the POST data with your file in file , but your receiving machine is looking for the file in the userfile variable. 目前您正在创建在你的文件中的POST数据file ,但您的接收设备正在寻找的文件userfile变量。 Your test fails because the variable names don't match, hence the message. 您的测试失败,因为变量名不匹配,因此出现了消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM