Jump to content

Uploading images and putting file name in a text field


BarneyJoe

Recommended Posts

I think I'm along the right track with this, but seem to be going wrong somewhere.

What I'm trying to do is have a form to upload info into a table. Each record also has an attached image, the file name needing to be in a file name field to point to the image.

So I have my form :

[CODE]<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">[/CODE]

where edit form action is pointing to a confirmation page.

My input file field :

[CODE]<input name="Image" type="file" size="55">
<input type="hidden" name="MAX_FILE_SIZE" value="25000" />[/CODE]

The code in the confirmation page to move the file to the relevant folder :

[CODE]<?php
move_uploaded_file ($_FILES['Image'] ['tmp_name'],
"/pathtofolder/{$_FILES['Image'] ['name']}")
?>[/CODE]

But the place I think I'm going wrong is the insert record code :

[CODE]if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO Carpets (CarpetRef, Carpet, Price, Image, Description, `Size`) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                      GetSQLValueString($_POST['CarpetRef'], "text"),
                      GetSQLValueString($_POST['Carpet'], "text"),
                      GetSQLValueString($_POST['Price'], "double"),
      GetSQLValueString($_FILES['Image']['name'], "text"),
                      GetSQLValueString($_POST['description'], "text"),
                      GetSQLValueString($_POST['Size'], "text"));[/CODE]

The record is being added, but the file isn't uploading...

Anyone spot where I've gone wrong?

Cheers,
Iain

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.