Jump to content

[SOLVED] Image Upload


iceblox

Recommended Posts

Hi Everyone,

 

I got this script and i want to post the name of the file into mysql databse. Im not sure what variable to use. The script allows multiple uploads via a loop which is what is confusing me..

 

Here is the upload form

 

 

 

<?
$max_no_img=4;  // Maximum number of images value to be set here
echo "<form method=post action=addimgck.php enctype='multipart/form-data'>";
echo "<table border='0' width='400' cellspacing='0' cellpadding='0' align=center>";
for($i=1; $i<=$max_no_img; $i++){
echo "<tr><td>Image $i</td><td>
<input type=file name='images[]' class='bginput'></td></tr>";
}
echo "<tr><td colspan=2 align=center><input type=submit value='Add Image'></td></tr>"; 

echo "</form> </table>";



?>

Here is the code that deals with the upload

 

 

 

<?


while(list($key,$value) = each($_FILES[images][name]))
{
if(!empty($value)){   // this will check if any blank field is entered

$filename = $value;    // filename stores the value

$add = "upimg/$filename";   // upload directory path is set

echo $_FILES[images][name][$key];     // uncomment this line if you want to display the file type

echo "<br>";                             // Display a line break

copy($_FILES[images][tmp_name][$key], $add);     //  upload the file to the server

chmod("$add",0777);                 // set permission to the file. 

}
}
?>

And this is script im trying to use to post the file name to my database but im not sure what to replace "name" with..

 

 

 

$result = $db->sql_query("INSERT INTO ".$prefix."_rev_pending (name)
			VALUES ('".forSql($_POST["name"])."');");

 

Any help would be appreciated

 

 

Phil

Link to comment
Share on other sites

so you want to add the NAME into the db? try this:

 

$file = $_FILE['images']['name'];
$addSQL = "INSERT INTO tbl_name (`id`,`name`)VALUES(NULL,'$file');";
$addQuery = mysql_query($addSQL);
if(!$addQuery){
echo "Error with our database";
} else {
echo "File name added sucessfully";
}

 

NOT TESTED but whould work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.