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
Share on other sites

You're copying the first one with:

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

You need to do the same with the second one, are you learning from an old book/tutorial? You're using some depreciated methods...

Link to comment
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');

}
?>

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.