Jump to content

[SOLVED] help w/ loops? uploading files...


mikefrederick

Recommended Posts

help please, this is the second time I posted this, I can't figure out how to upload multiple files. I have the form w/ 2 upload fields called image1 and image2. Then I am using this script which will upload the file names to a database and it will upload the first file to a folder on the site called "propertyimages/" and I need to know how to make the script also copy the other file to the folder. here is the script, which contains some additional information being submitted to the db:

 

 

<?php

require_once "connect.php";

 

$filename = $HTTP_POST_FILES['image1']['name'];

$filenametwo = $HTTP_POST_FILES['image2']['name'];

 

$path= "../propertyimages/".$filename;

$pathtwo= "../propertyimages/".$filenametwo;

if (copy($HTTP_POST_FILES['image1']['tmp_name'], $path))

{

 

$addname = $_POST['Addname'];

$addemail = $_POST['Addemail'];

$addphone = $_POST['Addphone'];

$adddesc = $_POST['Adddesc'];

$addact = $_POST['Addact'];

$addrates = $_POST['Addrates'];

$addamen = $_POST['Addamen'];

 

 

mysql_select_db($database_localhost, $localhost);

$query = "INSERT INTO addnew (addname,addemail,addphone,adddesc,addamen,addact,addrates,imageone,imagetwo) VALUES('$addname','$addemail','$addphone','$adddesc','$addamen','$addact','$addrates','$filename','$filenametwo')";

$Rs = mysql_query($query, $localhost) or die(mysql_error());

 

 

Header ('Location:index.php');

 

}

?>

Link to comment
https://forums.phpfreaks.com/topic/72415-solved-help-w-loops-uploading-files/
Share on other sites

This isn't the ideal way, but it should work.

<?php
require_once "connect.php";

$filename = $HTTP_POST_FILES['image1']['name'];
$filenametwo = $HTTP_POST_FILES['image2']['name'];

$path= "../propertyimages/".$filename;
$pathtwo= "../propertyimages/".$filenametwo;
if (copy($HTTP_POST_FILES['image1']['tmp_name'], $path) && copy($HTTP_POST_FILES['image2']['tmp_name'], $pathtwo))
{

$addname = $_POST['Addname'];
$addemail = $_POST['Addemail'];
$addphone = $_POST['Addphone'];
$adddesc = $_POST['Adddesc'];
$addact = $_POST['Addact'];
$addrates = $_POST['Addrates'];
$addamen = $_POST['Addamen'];


mysql_select_db($database_localhost, $localhost);
$query = "INSERT INTO addnew (addname,addemail,addphone,adddesc,addamen,addact,addrates,imageone,imagetwo) VALUES('$addname','$addemail','$addphone','$adddesc','$addamen','$addact','$addrates','$filename','$filenametwo')";
$Rs = mysql_query($query, $localhost) or die(mysql_error());


Header ('Location:index.php');

}
?>

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.