PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I was wondering if anyone could help me on this one? I'm trying to make an image gallery admin area in PHP and I'm trying to add a system kind of like the phpMyAdmin interface i.e. when adding a table you can add more rows- and when you add a new row all the <input>'s values are remembered. I know how to do this using every form element except for type='file'! Just to clarify:
<?php
$error = false;
if (isset($_POST['upload'])) {
if (!trim($_POST['title'])) {
$error = true;
}
if (!$error) {
# finish the job
}
}
?>
<html>
...
<form method="post" action="" enctype="multipart/form-data">
<input type="text" name="title" <?php if ($error) {echo 'value="'.htmlspecialchars($_POST['title']).'"';} ?> /><br />
<input type="file" name="image" <?php if ($error) {echo "HOW DO YOU GET THE USER INPUT BACK?";} ?> />
<input type="submit" name="upload" value="Upload" />
</form>
...
</html>
Any help would really be appreciated! I have a feeling it might not be possible because of something to do with security, but if it is it would save me looking into java!
ben.artiss wrote:I know how to do this using every form element except for type='file'!
Can't be done.
In your shoes I would turn the field into a readonly textbox with the name of the file that was uploaded and put a "Delete?" checkbox next to it.
But you can dynamically add stuff using JavaScript - and the form doesn't have to be submitted to do it.
Do you think it would be better to get the user to select the pics before going to a separate page to enter the information about each image? If so - do you know if it's possible to validate a file array (i.e. filesize/type) using ajax (backed up by php validation later)? Thanks for your reply