Forum Moderators: coopster
Basically I am trying to use a value from a form submitted on a previous page to form part of a file name. Everything is workig fine - files are uploaoding and remaning - however the value in the $frmTransNum variable is getting wiped for some reason....anyone any ideas?
<?php
//get the transaction number from the previous form submit...
$transNum=$frmTransNum;
//these two lines echo both values to the screen succesfully..
echo $frmTransNum. "<br>";
echo $transNum. "<br>";
/***********************************************
* Snippet Name : File Uploader *
* Scripted By : Hermawan Haryanto *
* License : GPL (General Public License) *
***********************************************/
$numoffile = 4;
// Fix path of your file to be uploaded, don't forget to CHMOD 777 to this folder
$file_dir = "/home/#*$!/public_html/files/";
if ($_POST) {
for ($i=0;$i<$numoffile;$i++) {
if (trim($_FILES['myfiles']['name'][$i])!="") {
$newFile = $file_dir.$_FILES['myfiles']['name'][$i];
//attempting here to use the value in the $transNum variable to prefix the file name...
$revisedFileName=$transNum."(".$i.")".$_FILES['myfiles']['name'][$i];
//the values in both $frmTransNum and $transNum dont echo out to the screen here and appear to have been wiped!
echo "frmTransNum = ".$frmTransNum;
echo "TransNum =". $transNum;
// a few echos just for goo measure!
echo "<br>";
echo "1=".$_FILES['myfiles']['name'][$i];
echo "2=".$file_dir.$_FILES['myfiles']['name'][$i];
echo "3=".$newFile;
echo "4=".$revisedFileName;
move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newFile);
echo "File " .$i. "Uploaded";
rename($newFile, $file_dir.$revisedFileName);
$j++;
}
}
}
if (isset($j)&&$j>0) print "Your file(s) has been uploaded.<br>";
print "<form method='post' enctype='multipart/form-data'>";
for($i=0;$i<$numoffile;$i++) {
print "<input type='file' name='myfiles[]' size='30'><br>";
}
print "<input type='submit' name='action' method=POST value='Upload'>";
print "</form>";
$transNum=$frmTransNum;
?>
[edited by: jatar_k at 5:39 pm (utc) on Jan. 27, 2006]
[edit reason] no urls thanks [/edit]
$temp = trim($_FILES['myfiles']['name'][$i]);
if (!(empty($temp)) ) {
//do whatever,
}
I would venture to guess the statements inside that 'if' aren't even being executed.....The variables shouldn't be out of scope. Well, give it a go and let us know.
--Nick