PHP read from uploaded text file?

后端 未结 3 1780
抹茶落季
抹茶落季 2021-01-31 03:25

If I upload a text file via a form, is it possible to output its contents directly from the $_FILES variable rather than saving it onto the server first? I know this is a secur

3条回答
  •  时光说笑
    2021-01-31 03:31

    Doing

    file_get_contents($_FILES['uploadedfile']['tmp_name']); 
    

    is valid however you should also check to make sure that the file was uploaded through a form and that no errors occurred during upload:

    if ($_FILES['uploadedfile']['error'] == UPLOAD_ERR_OK               //checks for errors
          && is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) { //checks that file is uploaded
      echo file_get_contents($_FILES['uploadedfile']['tmp_name']); 
    }
    

    A helpful link is http://us2.php.net/manual/en/features.file-upload.php

提交回复
热议问题