I cant upload files - php

I made a site, and I wand to upload files through a php form, but when I try to do so, I have the following error:405 Not Allowed
nginx. Can anyone help me?
I have checked my php.ini file, and file_uploads were on by default
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form method="post">
Enter Your Text Here:<br>
<input type="text" name="textdata"><br>
<input type="submit" name="submit">
</form>
</body>
</html>
<?php
if(isset($_POST['textdata']))
{
$data=$_POST['textdata'];
$fp = fopen('data.txt', 'a');
fwrite($fp, $data);
fclose($fp);
}
?>

Related

Download user input in textarea using HTML and PHP?

I'm working on learning PHP and I'm trying to essentially have the user enter input into two different text areas, and having the content downloaded into a single .txt file once they click the button. I know my code is extremely rough, I haven't found any solutions online for my specific case-scenario, but here it is:
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<meta charset="UTF-8" />
<link rel="stylesheet" href="./style.css" />
</head>
<div class="navbar">
Home
Resume
Projects
Contact
Social
Logout
</div>
<body>
<label for="textbox">Professional Summary</label>
<textarea id="textbox"></textarea>
<label for="bio">Brief Biography</label>
<textarea id="bio"></textarea>
<input type="button" id="homebt" value="Submit" />
</body>
</html>
<?php
if (isset($_POST['submit'])) {
$text = $_POST['bio'];
print ($text);
$filename = 'index.txt';
$string = $text;
$fp = fopen($filename, "w");
fwrite($fp, $string);
fclose($fp);
header('Content-disposition: attachment; filename=test.txt');
header('Content-type: application/txt');
readfile('test.txt');
die;
}
Currently nothing happens when the button is clicked. The entire code is in a file called adminIndex.php, and I have Apache Web Server running to open the file in my browser for testing purposes. If anyone could potentially help me out with what I'm doing wrong, I'd really appreciate it!
Edit (made the following changes to the end of the HTML code):
<form name='form' method='post'>
<label for="textbox">Professional Summary</label>
<textarea id="textbox"></textarea>
<label for="bio">Brief Biography</label>
<textarea id="bio"></textarea>
<input type="submit" id="homebt" value="Submit" name="submit" />
</form>
</body>

How can i create php forms which can i fill from command line (cmd)?

I have tried curl on html from but show error
curl -d user="Kirk" http://xxxxxxx.site/form.php
but in return
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>
</body></html>
I've also tried adding a user-agent, but I'm getting the same error.
i want to store value inside the "user"(html form element) to text file(stored on webserver) using command line. i am able to create this using web-based interface but i want it using command line.
my code for web-based interface
html:
<!DOCTYPE html>
<html>
<head>
<title>Store form data in .txt file</title>
</head>
<body>
<form action="data.php" method="post">
Enter Your Text Here:<br>
<input type="text" name="textdata"><br>
<input type="submit" name="submit">
</form>
</body>
</html>
php:
<?php
if(isset($_POST['textdata']))
{
$data=$_POST['textdata'];
$fp = fopen('log.txt', 'a');
fwrite($fp, $data);
fclose($fp);
}
?>

Simple HTML/PHP Refuses to work

Here is poster dot php
<?php
$FILENAME = "poster.php";
$txt = "data.txt";
if (isset($_POST['field1']) && isset($_POST['field2'])) { // check if both
fields are set
$fh = fopen($txt, 'a');
$txt=$_POST['field1'].' - '.$_POST['field2'];
fwrite($fh,$txt); // Write information to the file
fclose($fh); // Close the file
}
?>
Here is my HTML form
<!DOCTYPE html>
<html>
<head>
<title>Field 1 & 2</title>
</head>
<body>
<form action="poster.php" method="post">
What is your name?<br>
<input type="text" name="field1"><br>
<input type="text" name="field2"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
I tried everything to make this work when i put it in a debugger it says the file should end on the first line. When I run the file all i get is a white screen. I'm in desperate need of help.
You are not writing anything after appending your form data in your poster.php file. You can get the file contents in the following way...
Html form:
<!DOCTYPE html>
<html>
<head>
<title>Field 1 & 2</title>
</head>
<body>
<form action="poster.php" method="post">
What is your name?<br>
<input type="text" name="field1"><br>
<input type="text" name="field2"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
and in poster.php
<?php
$FILENAME = "poster.php";
$txt = "data.txt";
if (isset($_POST['field1']) && isset($_POST['field2'])) { // check if both
//fields are set
$fh = fopen($txt, 'a');
$txt=$_POST['field1'].' - '.$_POST['field2'].PHP_EOL;
fwrite($fh,$txt); // Write information to the file
fclose($fh); // Close the file
echo file_get_contents("data.txt");
}
?>
As per requirement, write PHP code and HTML code inside a single file and remove the action attribute of the form in the following code ...
<?php
//$FILENAME = "poster.php";
$txt = "data.txt";
if (isset($_POST['field1']) && isset($_POST['field2'])) { // check if both
//fields are set
$fh = fopen($txt, 'a');
$txt=$_POST['field1'].' - '.$_POST['field2'].PHP_EOL ;
fwrite($fh,$txt); // Write information to the file
fclose($fh); // Close the file
//echo file_get_contents("data.txt");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Field 1 & 2</title>
</head>
<body>
<form action="" method="post">
What is your name?<br>
<input type="text" name="field1"><br>
<input type="text" name="field2"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
action attribute of form should be file name where you submit your form.
<form action="action.php" method="post">
Here it is 'action.php' but you have to submit it on poster dot php.
please check it:
<form action="poster.php" method="post">
Form action will be your main file name(poster.php) and after form post, you can easily get all the form fields data on poster.php file.
you wotre this file name -> poster dot php means poster.php ?

PHP code is displayed instead of the output

Can someone please explain this code, i am following a very good book that was recommended to me and I have typed the code exactly as it is in the book. it displays the code instead of out, I am not sure what is wrong, the code is from a book called php solutions
<?php
// set the max upload size in bytes
$max = 51200;
if(isset($_POST['upload'])){
// define the path to the upload folder
$destination = 'C:\upload_test';
// move the file to the uplaod folder and rename it
move_uploaded_file($_FILES['image']
['tmp_name'], $destination.$_FILES['image']['setara']);
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mult</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<form action="" method="post" enctype="mutipar/form-data" id="uploadImage">
<p>
<label for="image">Upload image:</label>
<input type="hidden"name="MAX_FILE_SIZE" value="<?php echo $max; ?>">
<input type="file" name="image" id="image">
</p>
<p>
<input type="submit" name="upload" id="upload" value="Upload">
</p>
</form>
</body>
</html>
This is surely because you are writing PHP code in .html or .htm extension file try putting the code with .php extension file. It will resolve error.

My HTML/php page is presented as clear text in browser

I have this problem that my .php file is presented as clear text in the browser. I.e., the page is not transcoded in any way.
This is my html-fil with a form
<html>
<head>
</head>
<body>
<form id="myForm" action="commentNoJQ.php" method="post">
Name: <input type="text" name="name" />
Comment: <textarea name="comment"></textarea>
<input type="submit" value="Submit Comment" />
</form>
<p>Click on the button to load result.html file:</p>
<div id="stage" style="background-color:blue;">
STAGE
</div>
<input type="button" id="driver" value="Load Data" />
</body>
</html>
This is my .php file that the form is posting to. This file is presented as it is in the browser:
<html>
<head>
</head>
<body>
<?php
$myFile = "/Library/WebServer/testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $_POST["name"]);
fclose($fh);
?>
</body>
</html>
What is the problem?
It's php-related sine when I create a normal html-file to post to, the normal file is processed as it should be.
This is how it looks in the browser:
I checked the logs (access_log, error_log), no info at all. Are there any other logs I should check?
Using Apache 2.2 and Mac OSX 10.6.4
Thanks in advance!
/Niklas
PHP is not properly configured on Apache I think.
UPDATE: links http://php.net/manual/en/configuration.changes.php
http://www.php.net/manual/en/install.macosx.php

Categories