Jump to content

How to use a form selection with php to upload images [RESOLVED]


AdRock

Recommended Posts

I have a form and I want to choose the category based on a drop down selection so it inserts the the category into a database.

I need to know how I can chnage my form so instead of having to type something in a text box, I can use the selection box. At the moment it will work with the text box but not the selection.

How do i get it to work with my selection?

this is the code that works

<?php

//This is the directory where images will be saved
$target = "pics/";
$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form

$pic=($_FILES['photo']['name']);
if (!isset($_POST['desc'])) {
?>

<form enctype="multipart/form-data" action="<? $_SERVER['PHP_SELF']; ?>" method="POST"> 
Description: <input type="test" name="desc"><br>
Photo: <input type="file" name="photo"><br>
<input type="submit" value="Add">
</form>
<?}
else {
// Connects to your Database
// I've taken out the database stuff here

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ".basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}

//image manipulation stuff here
}
?>

I have got a form that works but not with [b]action="<? $_SERVER['PHP_SELF']; ?>"[/b]
[code]<form enctype="multipart/form-data" action="index.php?page=image" method="POST"> 
    <p style="margin-left:10px;">Gallery to upload to:<br>
    <select name="gallery" size="1">
    <option value="jack">Jack</option>
    <option value="honeylands">Honeylands</option>
    <option value="events">Events</option>
    <option value="art">Art Auction</option>
    </select>
        <p style="margin-left:10px;">Image to upload:<br>
        <input type="file" name="photo"><br>
        <P><input type="submit" name="submit" value="Upload Image" class="submit-button" style="margin-left:10px;"></p>
    </form>[/code]
Anyone know how I can use the second style form but use it on one php page instead of calling another script?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.