简体   繁体   中英

Handling file uploads in PHP

TLDR; How do I reference a temp file upload POSTed to a PHP script from within the PHP script?

I'm working on creating a web app (just for lab testing, doesn't need much security) that allows me to upload and aggregate XML&XLS files.

I've got everything worked out except for how to work with the file itself after the user POSTs it to the server using an HTML form.

I have a form that POSTs the file to the server, and I have a PHP script that is set up to do something with the file, but I'm falling short on understanding how to reference the uploaded file from the PHP script on the server.

EG:

<form action="Update_data.php" method="POST" enctype="multipart/form-data"> <input type="file" name="file" id="file"></br> <INPUT type="submit" name="submit" value="Submit"></br> </form>

and I'm vaguely aware that when the file is posted the file exists in a temp directory on the server until Update_data.php finishes executing. That's all fine and well, but I don't know what that directory would be, or even if I need to configure PHP.ini in some specific way to allow this.

So, what I'm asking is:

How do I reference a temp file upload POSTed to a PHP script from within the PHP script?

Thanks.

$_FILES['file']['tmp_name'] contains the file name of the uploaded file on the server.

Yu can use the move_uploaded_file() function to move the uploaded file to whatever location you need.

This manual page contains all the information you need: http://php.net/manual/en/features.file-upload.post-method.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM