TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-27-2010, 02:30 PM   #1 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default create .txt with text in the field?

Is it possible that if i have a form field and press create tag that i can create a text file in a specific folder.. where the text file would have a random name with random letters and numbers and the text file to contain what was specified in the text field... if so has anyone got any scripts or no of any scripts to do this? Thanks
Tim Dobson is offline  
Reply With Quote
Old 02-27-2010, 04:01 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

I don't have an existing script to do this, it is a fairly specific script so I doubt anyone else will have an exact match. However, this is quite easy to build. Here are the components you will need to get this together:

POST data
Random string generator
Create file
Write to file
__________________

Village Idiot is offline  
Reply With Quote
The Following User Says Thank You to Village Idiot For This Useful Post:
Tim Dobson (02-28-2010)
Old 02-27-2010, 08:34 PM   #3 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default

great stuff if anyone needs anything like this here is what i come out with and if anyone spots any errors i would appriciate u letting me know :D Thanks

PHP Code:
<?php
$thetag 
$_REQUEST["tag"];
//make a random number for the file name
$randnumb rand(09999999);
//make the file on the server and save it as .txt
$ourFileName $randnumb ".txt";
$ourFileHandle fopen($ourFileName'w') or die("can't open file");
fclose($ourFileHandle);
//open the file
$myFile $randnumb ".txt";
$fh fopen($myFile'w');
//start writing to the file
$stringData $thetag "\n";
fwrite($fh$stringData);
fclose($fh);
//we created the file and input the data to it now give them the URL
$thenewurl 'file location' $randnumb '.txt';
echo 
'Your upload was successful.. this is your URL <a href="file location' $randnumb '.txt">' $thenewurl '</a><BR>Save the url and give it to who you want to!';
?>
Tim Dobson is offline  
Reply With Quote
Old 02-27-2010, 10:13 PM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

If two numbers are generated the same you will write on to an existing file. You will want to check to make sure the file does not exist before continuing (do-while loops are useful for this).
__________________

Village Idiot is offline  
Reply With Quote
The Following User Says Thank You to Village Idiot For This Useful Post:
Tim Dobson (02-28-2010)
Old 02-27-2010, 10:41 PM   #5 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default

ah yes and i hit a bit of a snag also... how would i go about makeing the .txt file UTF-8? any ideas?
Tim Dobson is offline  
Reply With Quote
Old 02-27-2010, 11:51 PM   #6 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default

ok well i found a few things on the net but got a bit stook lol i need a bit of help...

i got this and put it in to my script

PHP Code:
// Fixes the encoding to uf8
function fixEncoding($thetag)
{
  
$cur_encoding mb_detect_encoding($thetag) ;
  if(
$cur_encoding == "UTF-8" && mb_check_encoding($thetag,"UTF-8"))
    return 
$thetag;
  else
    return 
utf8_encode($thetag);
// fixEncoding 

testing all this out i found that for some people the letters in the text file come out all messy and for some it come out perfectly fine... what could be causing this?? help appriciated!
Tim Dobson is offline  
Reply With Quote
Old 02-28-2010, 04:00 AM   #7 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default

well i got it figured out... it was due to people viewing it on there browser not having it set to the correct character encoding so this is problem solved! thanks for the help village :)
Tim Dobson is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Injection and mysql_real_escape_string Durux General 61 01-29-2013 12:20 PM
Create your own advanced WYSIWYG editor almsamim Javascript, AJAX, E4X 8 10-23-2008 06:41 PM
seeding an input text field with a string joby1 XHTML, HTML, CSS 2 01-03-2008 05:34 PM
PDF Creation - Help! Sam Granger General 7 10-31-2007 11:32 AM
Need your feedback Tanax Absolute Beginners 29 10-11-2007 04:50 PM


All times are GMT. The time now is 05:45 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design