uploading defined file – PHP



how can i upload a file on server.

$filename = "c:\file.txt";


i want to upload the $filename on the server is there a way for it.,


in most cases you use a form to upload the data from the client computer. (see also this article).

if you want to trigger that from the server side, you probably need to use cURL (no success guaranteed).


how about not using the input file.,

is there a functions in php that can upload just set the file path to be upload.
e.g. c:\upload.txt



Not PHP. I am 99.9% sure you can’t do that with any web language. The reason is that the web needs to go through your browser, if the clients browser let you access files like that, the security risk would be so massive, I would not be on the internet. Having said that, *maybe* something can be done with vb.net or asp, but if you did find that this was possible, the potential for stealing files would risk you being held accountable… For uploads, you are better off just trying a traditional upload input.

Anyway, not all computers will be set up the same with the same file path.


how about., instead of input file to use,
input text will be use as the file to be uploaded.


that is, so to speak, the classical way of form processing (only that you save the text to file in the end).



That is fine, but possibly a little overkill from totally automated to totally user submitted. Can you elaborate on what you’re trying to do and maybe we can give you better suggestions?

If not then a simple textarea which gets processed to become a file (look up "php create file" if you’re unsure) will do the trick. Just remember you really should be inspecting and sanitizing the user submitted data.

Rule #1 of PHP programming (and most user interacting languages) is trust no one!

What is in your text file you’re looking for? Better than a big textarea for users to put what they want, would be a series of inputs where you can check that the data matches what it should. Checking one large text block is more involed/risky than a few smaller ones.