如何在只知道路径的情况下移动临时文件?

时间:2016-06-25 00:58:59

标签: php laravel laravel-5

我只能得到临时文件路径,比如D:\ XAMPP \ tmp \ phpE185.tmp ...但是$ _FILE数组是null,因为我从url到另一个url进行传输。所以如何移动这个临时文件?

这是我的代码:

 class UserController extends Controller
{


public function getRank(){

    echo "waht";
}

public function uploadTrans(Request $request){

    $image = $request->image;
    $name = $request->name;

    $image = urlencode($image);
    $curlPost = "name=$name&image=$image";

    $uploadApi = "http://mdx.ittun.com/authprac/public/upload";
    $ch  = curl_init();
    curl_setopt($ch,CURLOPT_URL,$uploadApi);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$curlPost);
    $output = curl_exec($ch);
    curl_close($ch);
    echo $output;

}
public function upload (Request $request){


    $fileTempName = $request->image;
    print_r($fileTempName);

 //   here I just can get the temp file path..$_FILES array is null
    }
}

1 个答案:

答案 0 :(得分:0)

PHP为此目的有一个move_uploaded_file()函数。

由于您已使用标记了自己的问题,请参阅docs regarding uploaded files

$request->file('photo')->move($destinationPath);