soma56 Posted December 28, 2010 Share Posted December 28, 2010 I hope someone can help me out with this. What I would like to do is import a text file dircetly to a text area. I can't seem to find any examples on this (Yes I did search Google). I know how to upload but I'm not interested in storing files on the server - but rather just importing them directly to a textarea. Can anyone point me in the right direction? I can upload: <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> I can read: $myFile = "testFile.txt"; $fh = fopen($myFile, 'w') But I'm not interested in either of these as they are unnecessary steps (or are they?). Is there not a way to simply browse/import a text file directly to a textarea (or anywhere for that matter) without having to actually save the file to the server? Something like this: <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> //uploader.php if (isset($_POST['submit'])) { $content = $_POST['"grab the contents of the file"']; echo "<textarea>"; echo $content; echo "</textarea>"; } Quote Link to comment https://forums.phpfreaks.com/topic/222845-import-txt-directly-to/ Share on other sites More sharing options...
Maq Posted December 28, 2010 Share Posted December 28, 2010 Can you use file_get_contents? Quote Link to comment https://forums.phpfreaks.com/topic/222845-import-txt-directly-to/#findComment-1152320 Share on other sites More sharing options...
soma56 Posted December 28, 2010 Author Share Posted December 28, 2010 Can you use file_get_contents? Yes, I suppose I could. I was trying to avoid it. Here's the traditional logic: > Browse and upload file to server > Grab contents from uploaded file This is what I want to do: > Browse and upload contents of file to textarea Is this possible? Quote Link to comment https://forums.phpfreaks.com/topic/222845-import-txt-directly-to/#findComment-1152336 Share on other sites More sharing options...
QuickOldCar Posted December 28, 2010 Share Posted December 28, 2010 Can't just do an include? <form enctype="multipart/form-data" action="" method="POST"> Upload: <input name="file" type="file" /><br /> <input type="submit" value="Upload File" /> </form> <? $my_file = $_FILES["file"]["tmp_name"]; if (file_exists($my_file)) { include($my_file); } else { echo "No file to display"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/222845-import-txt-directly-to/#findComment-1152339 Share on other sites More sharing options...
QuickOldCar Posted December 28, 2010 Share Posted December 28, 2010 This would work better because can do returns for each line. <form enctype="multipart/form-data" action="" method="POST"> Upload: <input name="file" type="file" /><br /> <input type="submit" value="Upload File" /> </form> <? $my_file = $_FILES["file"]["tmp_name"]; if (file_exists($my_file)) { $data = file($my_file); $total = count($data); echo "<br />Total lines: $total<br />"; foreach ($data as $line) { echo "$line<br />"; } } else { echo "No file to display"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/222845-import-txt-directly-to/#findComment-1152347 Share on other sites More sharing options...
soma56 Posted December 29, 2010 Author Share Posted December 29, 2010 Thank you. I'm sure that will work fine. I appreciate your time. Quote Link to comment https://forums.phpfreaks.com/topic/222845-import-txt-directly-to/#findComment-1152427 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.