Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2006-02-13 23:58:48
- proph3t
- Member
- Registered: 2004-09-26
- Posts: 31
PHP not processing Form
I have a page set up where I needed to allow anyone upload a photo through a form. I set up everything but for some reason the PHP is not getting the data from the forms POST.
This is the code for the entire page:
<code>
<txp:output_form form=“header” />
<h2>Submit Image</h2>
<div class=“middlebox”>
<p>Submit your image here.</p>
<form name=“submit” method=“post” action=”<txp:site_url />submit/”>
Your Name: <input name=“name” type=“text” /><br /><br />
Your Image: <input type=“file” name=“image” size=“28” /><br /><br />
<input type=“submit” value=“Submit” />
</form>
</div>
<txp:php>
if($_POST[‘submit’])
{
if (!empty($_FILES[‘image’][‘name’]))
{
$extension = strrchr($_FILES[‘image’][‘name’], ‘.’);
$file_info = getimagesize($_FILES[‘image’][‘tmp_name’]);
if ($_FILES[‘image’][‘error’] === 0)
{
$image = $_POST[‘name’].$extension;
@move_uploaded_file($_FILES[‘image’][‘tmp_name’], $_SERVER[‘DOCUMENT_ROOT’].’/images/userimages/’.$image);
}
else
{
$error = 1;
}
}
}
echo $error;
</txp:php>
<txp:output_form form=“footer” />
</code>
When I submit the form it just reloads the page no uploads or errors.
Offline
#2 2006-02-14 00:19:25
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: PHP not processing Form
What’s your question?
You need to debug your code.
Alex
Offline
#3 2006-02-14 06:21:28
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: PHP not processing Form
To debug you might try starting with something as simple as: <txp:php>echo $_FILES['image']['name'];</txp:php>
and see what you get when you submit the form.
Offline
#4 2006-02-16 00:07:50
- proph3t
- Member
- Registered: 2004-09-26
- Posts: 31
Re: PHP not processing Form
<code><txp:php>echo $_FILES[‘image’][‘name’];</txp:php></code> is not outputting anything for me.
<code>echo $_POST[‘name’]</code> is working though..
Last edited by proph3t (2006-02-16 00:12:07)
Offline
#5 2006-02-16 00:11:51
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Offline
#6 2006-02-16 00:14:04
- proph3t
- Member
- Registered: 2004-09-26
- Posts: 31
Re: PHP not processing Form
Edited it above but just thought id write, the Name field is posting correctly but the image is not. Can’t find out why it wouldnt.
Offline
#7 2006-02-16 00:19:01
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Offline
#8 2006-02-16 04:14:54
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: PHP not processing Form
Oh, you forgot to update your form type: <form name="submit" method="post" enctype="multipart/form-data" action="<txp:site_url />submit/">
Offline
Pages: 1