Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-13-2009, 03:50 PM   PM User | #1
stephmck990
New to the CF scene

 
Join Date: Mar 2009
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
stephmck990 is an unknown quantity at this point
Adding a last name to multiple uploaded files.

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.

Code:
<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 Code:
<?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.
stephmck990 is offline   Reply With Quote
Old 03-14-2009, 12:59 AM   PM User | #2
sea4me
Regular Coder

 
sea4me's Avatar
 
Join Date: Jan 2009
Location: Damn, I don't know...
Posts: 389
Thanks: 11
Thanked 27 Times in 26 Posts
sea4me is an unknown quantity at this point
Try this:

PHP Code:
<?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 />"


?>
__________________
sea4me is offline   Reply With Quote
Users who have thanked sea4me for this post:
stephmck990 (03-18-2009)
Old 03-18-2009, 02:50 PM   PM User | #3
stephmck990
New to the CF scene

 
Join Date: Mar 2009
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
stephmck990 is an unknown quantity at this point
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:
PHP Code:
$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!

Last edited by stephmck990; 03-18-2009 at 02:56 PM..
stephmck990 is offline   Reply With Quote
Old 03-19-2009, 02:27 AM   PM User | #4
sea4me
Regular Coder

 
sea4me's Avatar
 
Join Date: Jan 2009
Location: Damn, I don't know...
Posts: 389
Thanks: 11
Thanked 27 Times in 26 Posts
sea4me is an unknown quantity at this point
lol I forgot that when I posted

Glad you got it to work!
__________________
sea4me is offline   Reply With Quote
Reply

Bookmarks

Tags
lastname, multiple, php, upload

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:09 PM.


Advertisement
Log in to turn off these ads.