...

View Full Version : Adding a last name to multiple uploaded files.



stephmck990
03-13-2009, 04:50 PM
Okay, so you guys had answered my question on how to do this on a single file, but now I need some help with doing it on multiple uploaded files.


<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="multiple_upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td width="100%">
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<label><font size="1">Please enter your name, last name first, separated
by an underscore and number photo correctly. (ex. Smith_John):</font></label>
<br />
<input name="lastname" type="text" id="lastname" size="25">
</font></td>
</tr>
<tr>
<td> <input name="ufile[]" type="file" id="ufile[]" size="25" /></td>
</tr>
<tr>
<td> <input name="ufile[]" type="file" id="ufile[]" size="25" /></td>
</tr>
<tr>
<td> <input name="ufile[]" type="file" id="ufile[]" size="25" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload Photos" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>


And...



<?php



$path1= "uploads/".$HTTP_POST_FILES['ufile']['name'][0];
$path2= "uploads/".$HTTP_POST_FILES['ufile']['name'][1];
$path3= "uploads/".$HTTP_POST_FILES['ufile']['name'][2];

$target_path = $target_path . rawurlencode( $_POST['lastname']);

copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);
copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3);

echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>";
echo "<img src=\"$path1\" width=\"75\" height=\"75\">";
echo "<P>";

echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>";
echo "<img src=\"$path2\" width=\"75\" height=\"75\">";
echo "<P>";

echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>";
echo "<img src=\"$path3\" width=\"75\" height=\"75\">";


$filesize1=$HTTP_POST_FILES['ufile']['size'][0];
$filesize2=$HTTP_POST_FILES['ufile']['size'][1];
$filesize3=$HTTP_POST_FILES['ufile']['size'][2];


if($filesize1 && $filesize2 && $filesize3 != 0)
{
echo "<P>We have recieved your files";
}

else {
echo "ERROR.....";
}


if($filesize1==0) {
echo "There is an error with your first file";
echo "<BR />";
}

if($filesize2==0) {
echo "There is an error with your second file";
echo "<BR />";
}

if($filesize3==0) {
echo "There is an error with your third file";
echo "<BR />";
}

?>



Is there any way to take the text typed into the 'lastname' textbox and rename the uploaded files to have their last name at the beginning of the file names?

Thanks in advance. :)

sea4me
03-14-2009, 01:59 AM
Try this:


<?php
$lastname = $_POST['lastname'];

//do some checking of the last name HERE!!!

$separator = "_"; // the files will have a separator between the last name and the upload name

$path1= "uploads/".$lastname1.$separator.$HTTP_POST_FILES['ufile']['name'][0];
$path2= "uploads/".$lastname2.$separator.$HTTP_POST_FILES['ufile']['name'][1];
$path3= "uploads/".$lastname3.$separator.$HTTP_POST_FILES['ufile']['name'][2];

$target_path = $target_path . rawurlencode( $_POST['lastname']);

copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);
copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3);

echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>";
echo "<img src=\"$path1\" width=\"75\" height=\"75\">";
echo "<P>";

echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>";
echo "<img src=\"$path2\" width=\"75\" height=\"75\">";
echo "<P>";

echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>";
echo "<img src=\"$path3\" width=\"75\" height=\"75\">";


$filesize1=$HTTP_POST_FILES['ufile']['size'][0];
$filesize2=$HTTP_POST_FILES['ufile']['size'][1];
$filesize3=$HTTP_POST_FILES['ufile']['size'][2];


if($filesize1 && $filesize2 && $filesize3 != 0)
{
echo "<P>We have recieved your files";
}

else {
echo "ERROR.....";
}


if($filesize1==0) {
echo "There is an error with your first file";
echo "<BR />";
}

if($filesize2==0) {
echo "There is an error with your second file";
echo "<BR />";
}

if($filesize3==0) {
echo "There is an error with your third file";
echo "<BR />";
}

?>

stephmck990
03-18-2009, 03:50 PM
Gah, nope. Still just uploading with the file name. :/

EDIT: Buuuut I got it to work.
Took the numbers out from behind the lastnames here:

$path1= "uploads/".$lastname1.$separator.$HTTP_POST_FILES['ufile']['name'][0];
$path2= "uploads/".$lastname2.$separator.$HTTP_POST_FILES['ufile']['name'][1];
$path3= "uploads/".$lastname3.$separator.$HTTP_POST_FILES['ufile']['name'][2];

Works wonderfully!

Thanks so much!

sea4me
03-19-2009, 03:27 AM
lol I forgot that when I posted :)

Glad you got it to work! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum