doubao6681 2018-08-17 05:20
浏览 34

在服务器中上传文件

//index file

<form action="index.php" method="post" enctype="multipart/form-data">
    <input type="file" name="image"/>
    <input type="submit" value="Post"/>
</form>

<?php
  if(isset($_FILES['image']['tmp_name'])){
    $ch = curl_init();

    $cfile =new CURLFile($_FILES['image']['tmp_name'],$_FILES['image']['type'],$_FILES['image']['name']);
    $data = array('myimage' => $cfile);

    curl_setopt($ch,CURLOPT_URL,"http://localhost/curl/send_file_to_server/uploads.php");
    curl_setopt($ch,CURLOPT_POST,true);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data);

    $response = curl_exec($ch);
    if($response == true){
        echo "File Posted";
    }
    else{
        echo "Error: ".curl_error($ch);
    }
  }
?>

//uploads file

<?php
  if(isset($_FILES['myimage']['tmp_name'])){
    $path = "uploads/".$_FILES['myimage']['tmp_name'];
    move_uploaded_file($_FILES['myimage']['name'],$path);
  }
?> 

Here I want to store an image of index.php into the uploads.php. I am using curl method of php.The file print that file posted but not store in the uploads folder.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度