I have to integrate with a relatively goofy system currently in place. Hence the goofy code. What I need is to have the user choose a pdf to upload. The pdf is then saved as cusip_HLD.pdf for as many cusips as there is. For example
$fundID = 8
SELECT cusip FROM shareClass WHERE fundID = '$fundID'
Will return
| CUSIP |
| 1234567 |
| 7894561 |
| 3546841 |
The code that is currently in place is the following, but while it echos it saved several times, the move_uploaded_file
appears to pull the file out of temp storage.
while($row = mysql_fetch_assoc($getCusipsResult)){
$cusip = $row['cusip'];
$fullFileName = $cusip."_HLD.pdf";
move_uploaded_file($_FILES["file"]["tmp_name"], "pdf/".$fullFileName);
echo "Stored in: pdf/".$fullFileName;
}
EDIT: How can I fix the code so the need stated above is fulfilled?
You can only MOVE the uploaded file once. After that it's no longer in the temp upload dir (because you moved it). If you need to create multiple copies of the file, then use a copy
command instead, e.g.
while($row = ...) {
$fullFileName = ...;
if (is_uploaded_file($_FILES['file']['tmp_name'])) {
copy($_FILES['file']['tmp_name'], "pdf/$fullFileName");
}
}
if these files are not going to be modified by the users, then consider using a hardlink instead, so only one copy of the file is saved, and simply point the other "copies" at the original.