Recommended Posts

Hi all, I use MS Access to keep track of income at various kiosks and each day I create a text file which I would like to upload to my server and save the data to my tables so I can publish the results on a website. My question is about the uploading. The W3 schools example uses a form to pick the file and then uploads with php, as several other help sites have suggested. I already know the name of the file - it's not like a user picking one from his computer - so I'd like to skip the user interface and just tell the 'uploader' which file to use. I just want to click a button and have the whole thing done with, exactly the same every day. I think I've got an idea but wanted to run it by you experts to see if I'm on the right track. I believe the key is to assign $FILES with the name of the file on my computer, instead of getting it from the form and then using that in the move_uploaded_file method to move it to a folder on my server. But I'm not sure how to assign a value to $FILES and what other background things I may have to do to get it to work. Or is it as simple as coding $myFile = $FILES["C:/Users/me/myfolder/myFile.txt"] and then moving it to my target file on the server? I don't want to do a test on it as I realize how much things could get messed up. And I do know there are plug-ins that could do the job, but I want to understand the basics of uploading and code it myself. Thank you for your help.

I thought I'd add what I'm hoping could be my solution - but I'm not holding my breath - it seems too simple. Please explain to me what needs to be done.

<?php
$myFile = $FILES["C:/Users/Me/ThisFolder/myFile.txt"];// file on my computer
$target ="uploads/newKettleInfo.txt";// where to put the uploaded fileif(move_uploaded_file($myFile, $target_file)){
echo "The file ".$myFile." has been uploaded.";}else{
echo "Sorry, there was an error uploading your file.";}?>

Share this post

Link to post

Share on other sites

Thanx for the reply. Maybe I'm not understanding what I need to do - I think I want to upload because I want to use php to do something with the file on the server. Right now I am opening my phpAdmin every day and entering my daily data by hand which is getting kind of tedious. I do want to COPY my data from a text file on my computer, but I thought that to get it on the server I had to UPLOAD. I know I could go to the file manager on the server and click upload and put the file wherever I want, but I wanted to make it automatic so I would have a button on the website to run the php to upload the file and then add the info to my database, parsing it using php.

I think I see what your saying - maybe I don't need $FILES at all because that has to do with the Form action and Post method? Maybe I need to specify the address of the file on my computer in a different way? I would think this would be possible to do, I just don't have the correct coding to do it. I hope you can help me figure this out; please be specific as I'm still learning.

Share this post

Link to post

Share on other sites

Thank you very much - I was getting the feeling that it couldn't be totally automatic. I guess I'll just have to take 30 seconds out of my day to upload the txt file to my server. Thank you for the link and your help. Happy Holidays to you!