How to resolve the C:\fakepath?

后端 未结 13 1725
梦如初夏
梦如初夏 2020-11-21 13:34

This is my upload button.



        
13条回答
  •  执念已碎
    2020-11-21 14:07

    Hy there , in my case i am using asp.net development environment, so i was want to upload those data in asynchronus ajax request , in [webMethod] you can not catch the file uploader since it is not static element , so i had to make a turnover for such solution by fixing the path , than convert the wanted image into bytes to save it in DB .

    Here is my javascript function , hope it helps you:

    function FixPath(Path)
             {
                 var HiddenPath = Path.toString();
                 alert(HiddenPath.indexOf("FakePath"));
    
                 if (HiddenPath.indexOf("FakePath") > 1)
                 {
                     var UnwantedLength = HiddenPath.indexOf("FakePath") + 7;
                     MainStringLength = HiddenPath.length - UnwantedLength;
                     var thisArray =[];
                     var i = 0;
                     var FinalString= "";
                     while (i < MainStringLength)
                     {
                         thisArray[i] = HiddenPath[UnwantedLength + i + 1];
                         i++;
                     }
                     var j = 0;
                     while (j < MainStringLength-1)
                     {
                         if (thisArray[j] != ",")
                         {
                             FinalString += thisArray[j];
                         }
                         j++;
                     }
                     FinalString = "~" + FinalString;
                     alert(FinalString);
                     return FinalString;
                 }
                 else
                 {
                     return HiddenPath;
                 }
             }
    

    here only for testing :

     $(document).ready(function () {
                 FixPath("hakounaMatata:/7ekmaTa3mahaLaziz/FakePath/EnsaLmadiLiYghiz");
             });
    // this will give you : ~/EnsaLmadiLiYghiz
    

提交回复
热议问题