cqpCow před 2 roky
rodič
revize
65e5a27d69
1 změnil soubory, kde provedl 11 přidání a 6 odebrání
  1. 11 6
      app/Http/Controllers/Api/TestController.php

+ 11 - 6
app/Http/Controllers/Api/TestController.php

@@ -1266,7 +1266,8 @@ public function testFile(Request $request){
     $file = $request->file('file');
     $filename = $this->uploadItemBillFile($file);
     // 使用 'public' 磁盘驱动来获取文件路径
-    $filePath = Storage::disk('public')->path('big_tree\\'.$filename);
+    $filePath = Storage::disk('public')->path('big_tree/'.$filename);
+    $realPath = realpath($filePath);
 
     $url = $data['url'];
     $header = $data['header'];
@@ -1276,6 +1277,7 @@ public function testFile(Request $request){
 
     curl_setopt_array($curl, array(
         CURLOPT_URL => $url,
+//        CURLOPT_VERBOSE => true,
         CURLOPT_RETURNTRANSFER => true,
         CURLOPT_ENCODING => '',
         CURLOPT_MAXREDIRS => 10,
@@ -1283,10 +1285,12 @@ public function testFile(Request $request){
         CURLOPT_FOLLOWLOCATION => true,
         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
         CURLOPT_CUSTOMREQUEST => 'POST',
-        CURLOPT_POSTFIELDS => ['file' => new \CURLFile($filePath)],
-//        CURLOPT_HTTPHEADER => $header,
+        CURLOPT_POSTFIELDS => ['file' => new \CURLFile($realPath)],
+//        CURLOPT_HTTPHEADER => ["Content-Type:application/json;charset=UTF-8"],
     ));
     $response = curl_exec($curl);
+//    $info = curl_getinfo($curl);
+
     curl_close($curl);
     Storage::disk('public')->delete('big_tree\\'.$filename);
 
@@ -1297,14 +1301,15 @@ public function testFile(Request $request){
         // 获取文件相关信息
         $ext = $file->getClientOriginalExtension();     // 扩展名
         $realPath = $file->getRealPath();   //临时文件的绝对路径
+        $filename = $file->getClientOriginalName();//上传文件名
 
         // 上传文件
-        $file_name = time().rand(1000,9999);
-        $filename =  $file_name.'.' . $ext;
+//        $file_name = time().rand(1000,9999);
+//        $filename =  $file_name.'.' . $ext;
         // 使用我们新建的uploads本地存储空间(目录)
         Storage::disk('public')->put('big_tree/'.$filename, file_get_contents($realPath));
 
-        return $file_name. '.' .$ext;
+        return $filename;
     }
 
 public function testaa(Request $request){