I’m uploading a txt file to a server, but I want to format it with a little RegEx first. How would I have it sent to the PHP script, change its contents, then upload it?
I get its filename from $_FILES["userinput"]["name"] and then save the contents of it with file_get_contents() and then edit it. But now how do I move this edited string to the server instead of the original, unedited file.
I was thinking of creating a new .txt file and filling it with the contents of the string then uploading that, but that doesn’t seem very efficient. Is there a way to just modify the file that’s trying to be uploaded?
Before a file is uploaded in PHP it is saved as a temp file, That file contains the contents of the file and when you upload the file it basically uploads your temp file. So all you would need to do is to change the contents of the file with the name
$_FILES['userinput']['tmp_name'];and when you upload it’ll grab your modified temp file and upload it.Editing the file would be easy, Here is an example of how you would do this:
NOTE: Please click the green tick or 1 point up button if I’ve helped!