Jump to content

Upload file script / form within a different form?


wmguk

Recommended Posts

Hey guys,

 

I have a product insert form,

 


 

however I want to upload an image for the product I am making.

 

I found this code

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

 

but my insert code already uses and form, and I have googled two forms etc and it looks like thats something you cant do. This is my complete product creation page.

<form name="create" method="post" action="scripts/create.php">
            <p> </p>
            <table width="420" border="0" align="center" cellpadding="0" cellspacing="0" class="boxes">
              <tr>
                <td class="rightmenu">Name:</td>
                <td class="rightmenu"> </td>
                <td><input name="name" type="text" class="boxes" id="name" size="21" /></td>
                <td colspan="3" align="center" valign="middle"> </td>
              </tr>
              <tr>
                <td class="rightmenu">Style:</td>
                <td width="5" class="rightmenu"> </td>
                <td>
                  <select name="style" class="boxes" id="style">
                    <option value="Glass">Glass</option>
                    <option value="Mosaic">Mosaic</option>
                    <option value="Natural">Natural</option>
                    <option value="Ceramic" selected="selected">Ceramic</option>
                    <option value="Designer">Designer</option>
                  </select>                </td>
                  <td colspan="3" align="center" valign="middle"><?PHP //SELECT THE PICTURE
                </td></tr><tr>
                <td class="rightmenu">Colour:</td>
                <td width="5" class="rightmenu"> </td>
                <td><select name="colour" class="boxes" id="colour">
                  <option value="Beige">Beige</option>
                  <option value="Black">Black</option>
                  <option value="Blue">Blue</option>
                  <option value="Green">Green</option>
                  <option value="Grey">Grey</option>
                  <option value="Orange">Orange</option>
                  <option value="Red / Terr">Red / Terr</option>
                  <option value="White">White</option>
                  <option value="Yellow">Yellow</option>
                  <option value="Others">Others</option>
                                </select></td>
                <td colspan="3" align="center" valign="middle"> </td>
              </tr>
              
              <tr>
                <td class="rightmenu"> </td>
                <td width="5" class="rightmenu"> </td>
                <td> </td>
                <td colspan="3" align="center" valign="middle"> </td>
              </tr>
              <tr>
                <td class="rightmenu">Clearance?</td>
                <td width="5"> </td>
                <td><input name="clear" type="checkbox" class="boxes" id="clear"></td>
                <td class="rightmenu">Special Offer?</td>
                <td width="5"> </td>
                <td><input name="special" type="checkbox" class="boxes" id="special"></td>
                </tr>
              <tr>
                <td> </td>
                <td width="5"> </td>
                <td> </td>
                <td colspan="3" align="center" valign="middle"> </td>
              </tr>
              <tr>
                <td bgcolor="#6699DD"> </td>
                <td bgcolor="#6699DD"> </td>
                <td bgcolor="#6699DD"> </td>
                <td bgcolor="#6699DD"> </td>
                <td bgcolor="#6699DD"> </td>
                <td bgcolor="#6699DD"> </td>
              </tr>
              <tr>
                <td width="90"> </td>
                <td width="5"> </td>
                <td> </td>
                <td width="90"> </td>
                <td width="5"> </td>
                <td width="90"> </td>
              </tr>
<?PHP
echo "<input type='hidden' name='count' value='$count'>";
for($i = 1;$i <= $count;$i++)
{
?>
<tr><td class="rightmenu">Size:</td>
<td width="5"> </td>
<td><?PHP echo "<input type='text' class='boxes' name='size_$i' value=''>"; ?></td>
<td class="rightmenu">Cost:</td>
<td width="5"> </td>
<td><?PHP echo "<input type='text'  class='boxes' name='price_$i' value=''>"; ?></td></tr>
<?PHP } ?>

<tr><td colspan="6" align="center" valign="middle">
<input name="create" type="submit" class="buttons" id="create" value="Create Product"></td></tr></table></form>

 

How could i do a simple browse, select, image within the existing form i am using? I just cant seem to work it out.

 

Cheers guys

Drew

You add the enctype value to your form, copy over the 'file' input box and process the upload when the form has been sent. It's that simple!

 

excellent :) thank you again!! Also, i want to insert the name into a database field called pic...

 

woo hoo :)

 

this is the script im using now:

 

<?
// Where the file is going to be placed 
$target_path = "images/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
$_FILES['uploadedfile']['tmp_name']; 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file called: ".  basename( $_FILES['uploadedfile']['name']). 
    ", please try again!";
} 

 

however i get the failed message, ive checked the folder its uploading to is 777, any idea why its not able to upload them?

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.