iT邦幫忙

0

php檔案上傳

  • 分享至 

  • twitterImage

google雲端上傳檔案時相同檔名會增加(i),在刪除後在新增這個(i會繼續累加) 如下圖:
https://ithelp.ithome.com.tw/upload/images/20210624/20129366J4ywZIoNfO.png
我刪除了相同檔名的(1)後面上傳相同檔名會繼續加,我該如何實現此邏輯?
以下是現在的php

if (in_array($fileExtension, $allowedfileExtensions)){

 // 判斷哪種檔案放哪個FILE
 $wherefile='';
 if($fileExtension=='apk'){
     $wherefile='apkfile/';
 }else{
     $wherefile='ipafile/';
 }
 $target_path='uploaded_files/'.$wherefile;
 $target_path.= $fileName;

 if(move_uploaded_file($_FILES['uploadedFile']['tmp_name'],$target_path)){
              $add_data=array('name'=>$fileName,'script'=>$description,'time'=>$fileTime,'file_size'=>($fileSize/1000).'KB');
  $record_json = file_get_contents("record.json");
  $record_array=json_decode($record_json, true);
  array_push($record_array,$add_data);
  $new_record_json = jsonFormat($record_array);
  file_put_contents("record.json",$new_record_json);//寫入
    }
  }
  else{
    $message = '可上傳的檔案類型' . implode(',', $allowedfileExtensions);
  }

沒用資料庫紀錄用json紀錄資訊
這是我現在上傳後會產生的json格式

[
    {
        "name":"\u8f49\u78bc\u6e2c\u8a66\u529f\u84cb\u92b9abc\u8f49\u78bc\u6e2c\u8a66.ipa",
        "script":"",
        "time":"2021-06-24 14:23:54",
        "file_size":"0KB"
    },
    {
        "name":"111.ipa",
        "script":"",
        "time":"2021-06-24 14:23:59",
        "file_size":"0KB"
    },
    {
        "name":"222.apk",
        "script":"",
        "time":"2021-06-24 14:24:03",
        "file_size":"0KB"
    },
    {
        "name":"\u8f49\u78bc\u6e2c\u8a66\u529f\u84cb\u92b9abc\u8f49\u78bc\u6e2c\u8a66.apk",
        "script":"",
        "time":"2021-06-24 14:24:06",
        "file_size":"0KB"
    }
]
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
小魚
iT邦大師 1 級 ‧ 2021-06-24 19:26:11

你沒有記次數啊,
如果你要加上數字應該要記次數吧.

我要發表回答

立即登入回答