LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-01-2011, 11:22 AM   #1
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Rep: Reputation: 57
Uploading a text into a webpage from command line


Hi,

Please find my webpage PHP below.
I would like to enter "Hello, in the main inputbox field" below (You are editing: textfile.txt)
and click "SAVE" directly from command line.


Sort of :
wput_php "hello, in the main inputbox field" click save, and here is it. the text would be uploaded.

Can it be realized? Would you have the code please?

many thanks in advance...

PHP Code:
<?
define
("DEFAULT_FILE""textfile.txt"); // Default file that is used when ?file= is not defined.

/// END CONFIG, START MAIN SCRIPT //

if ($_GET[file] == ""
    
$file DEFAULT_FILE;
else
    
$file $_GET[file];

if (
$_POST[update] == "true") {
    
$fh fopen($file'w') or die("Can't open file.");
    
fwrite($fhstripslashes($_POST[body]));
    
fclose($fh);
}


if (
$_POST[bsubmit]=="Update")
{
echo 
' <span style="font-weight: bold" > '  ;
echo 
' ====>>>   Read/updated !   <<<==== ' ;
echo 
'</span> ' ;
echo 
'</div> ' ;
echo 
'<div style="text-align: left;"> '  ;
}


if (
$_POST[bsubmit]=="Shopping")
{
echo 
' <span style="font-weight: bold" > '  ;
echo 
' ====>>>   Shopping !   <<<==== ' ;
echo 
'</span> ' ;
echo 
'</div> ' ;
define("DEFAULT_FILE""shopping.txt");
echo 
'<div style="text-align: left;"> '  ;
}

if (
$_POST[bsubmit]=="Shopping")
{
echo 
' <span style="font-weight: bold" > '  ;
echo 
' ====>>>   To Do List !   <<<==== ' ;
echo 
'</span> ' ;
echo 
'</div> ' ;
define("DEFAULT_FILE""todo.txt");
echo 
'<div style="text-align: left;"> '  ;
}


if (
$_POST[bsubmit]=="Default")
{
echo 
' <span style="font-weight: bold" > '  ;
echo 
' ====>>>   Textfile List !   <<<==== ' ;
echo 
'</span> ' ;
echo 
'</div> ' ;
define("DEFAULT_FILE""textfile.txt");
echo 
'<div style="text-align: left;"> '  ;
}





if (
$_POST[bsubmit]=="Reset")
{
echo 
' <span style="font-weight: bold" > '  ;
echo 
' ====>>>   Reset !   <<<==== ' ;
echo 
'</span> ' ;
echo 
'</div> ' ;
echo 
'<div style="text-align: left;"> '  ;
$fh fopen($file'w') or die("Can't open file.");
fwrite($fhstripslashes("Reset performed"));
fclose($fh);


}




if (
$_POST[bsubmit]=="Save")
{

    
date_default_timezone_set('UTC');

    
$fh fopen($file'w') or die("Can't open file.");
    
fwrite($fhstripslashes($_POST[body]));
    
fclose($fh);
echo 
' <span style="font-weight: bold" > '  ;
echo 
' ====>>>   Saved !   <<<==== ' ;
echo 
'</span> ' ;
echo 
'</div> ' ;
echo 
'<div style="text-align: left;"> '  ;


}



?>
<html><head><title>BCSNotepad</title></head><body>
<center><table width=400><tr><td style='border: 2px dashed #003b53; padding:10px; font-family:verdana; font-size:10px; color: #003b53;' align='center'>
You are editing: <i><?=$file?></i><br><br>
<form action='<?=$PHP_SELF?>?file=<?=$file?>' method='post'>


<form action='<?=$PHP_SELF?>?file=<?=$file?>' method='post'>
<textarea name='body'  rows="25" cols="100"  style="font-family: Verdana; padding: 5px; background-color: LightYellow"   ><?
if (file_exists($file))
    
readfile($file);
else
    
$message "The file ".$file." does not exist and will<br>be created when you click Save.<br><br>";
?></textarea><br><br>
<?=$message?> 


<FORM action="notepad.php" method="post">
    <INPUT type="submit" name="bsubmit" value="Update">
    <INPUT type="submit" name="bsubmit" value="Save">
    <INPUT type="submit" name="bsubmit" value="Reset">

</FORM>



</form>
</td></tr></table></center>
</body></html>

Last edited by frenchn00b; 04-01-2011 at 11:23 AM.
 
Old 04-01-2011, 12:01 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,235

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
How do I make a POST request with curl
 
Old 04-01-2011, 03:42 PM   #3
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Original Poster
Rep: Reputation: 57
Quote:
Originally Posted by dugan View Post


thanks, sounds promising... -d is cool
but I still fight to get it work, curl output gives me this

I would like to enter values into "body", and then click on save

Not working
Quote:
curl -d "body=tralala&submit=Save" www.example.com/mypage.php


PHP Code:
<form action='?file=textfile.txt' method='post'>
<
textarea name='body'  rows="25" cols="100"  style="font-family: Verdana; padding: 5px; background-color: LightYellow"   >test</textarea><br><br>
 


<
FORM action="notepad.php" method="post">
    <
INPUT type="submit" name="bsubmit" value="Update">
    <
INPUT type="submit" name="bsubmit" value="Save">
    <
INPUT type="submit" name="bsubmit" value="Reset">

</
FORM

Last edited by frenchn00b; 04-01-2011 at 03:44 PM.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem of uploading webpage with ftp fadu Linux - Newbie 1 07-03-2009 11:15 AM
problem of uploading webpage with ftp fadu Linux - Newbie 1 07-03-2009 09:50 AM
VI text editor in command line InSane103 Linux - Software 4 07-09-2003 09:04 PM
Command line Text Terri Linux - General 8 04-05-2002 03:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration