Getting complete PATH of uploaded file - PHP

后端 未结 5 1661
-上瘾入骨i
-上瘾入骨i 2020-11-28 12:57

I have a form(HTML, PHP) that lets the end user upload a file to update the database(MySQL) with the records in the uploaded file(specifically .csv). However, in the phpscri

相关标签:
5条回答
  • 2020-11-28 13:10

    name refers to the filename on the client-side. To get the filename (including the full path) on the server-side, you need to use tmp_name:

    $handle = fopen($_FILES["UploadFileName"]["tmp_name"], 'r');
    
    0 讨论(0)
  • 2020-11-28 13:12

    I use like this...

    <?php
    $NameOriginal = $_FILES["UploadFileName"]['name'];
    $Typo_Image = $_FILES["UploadFileName"]['type'];
    $name_Temp = $_FILES["UploadFileName"]['tmp_name']; 
    ?>
    
    0 讨论(0)
  • 2020-11-28 13:25
    $target='uploads/'.basename($_FILES['UploadFileName']['name']);
    
    if(move_uploaded_file($_FILES['UploadFileName']['tmp_name'],$target)) {
    
         //Insert into your db
    
         $fp = fopen($target, "r");
    }
    
    0 讨论(0)
  • 2020-11-28 13:25

    Use the following code,

    $handle = fopen($_FILES["UploadFileName"]["tmp_name"], 'r');
    
    0 讨论(0)
  • 2020-11-28 13:28

    I wrote like this:

    $filePath = realpath($_FILES["file"]["tmp_name"]);
    

    This gave me the full path to the uploaded file in PHP. If you find 0 bytes problem in file download, just modify this content-lenght line like this

    header("Content-Length: ".filesize($filePath));
    

    Where $filePath should be absolute path to file not just file handle.

    0 讨论(0)
提交回复
热议问题