I have a form that points to the script below and that form has a function for uploads. It used to work fine until I added the part in the script that creates a new page with the information submitted in the form.
It's supposed to work like this: Form --> publishform.php (the script below) --> new page created. (In other words, user fills out the form and uploads files on that form, the form points to publishform.php, which processes the data and puts the data on a new page using the person's first name as the page name.php.)
This link (http://www.arospeed.net/sponsors/ERICA.php) is the page that is created using the data from the form. The images all upload correctly onto my server, but for some reason the correct name of the image is not shown on the newly created page. It comes out as namejpg instead of name.jpg in the html so the pictures will not show. Right click on one of the red X's, go to properties and look at Address to see that the file is named wronged (the reason why they show up as red x's).
Here is my code. Please help!
<?php
include ("sponsors_header.php");
?>
<?
// THIS IS THE FILE UPLOAD FUNCTION
$path_to_file = './sponsors/images/';
$files = $_FILES['files'];
if (!ereg("/$", $path_to_file))
$path_to_file = $path_to_file."/";
$i = 0;
$imgname = array();
foreach ($files['name'] as $key=>$name) {
if ($files['size'][$key]) {
// clean up file name
$name = ereg_replace("[^a-z0-9._]", "",
str_replace(" ", "_",
str_replace("%20", "_", strtolower($name)
)
)
);
$location = $path_to_file.$name;
// while (file_exists($location))
// $location .= ".copy";
copy($files['tmp_name'][$key],$location);
unlink($files['tmp_name'][$key]);
echo "\n
Successfully uploaded file: $name.<br>";
$imgname[$i++] = $name;
}
}
?>
<br>
<a href="http://www.arospeed.net/sponsors/<?php echo $FirstName,$LastName; ?>.php">Click here</a> to see the page you just created.
// THIS CREATES THE NEW PAGE THAT IS SUPPOSED TO SHOW THE UPLOADED IMAGES AND FORM INFORMATION
<? $page = <<<ENDHTML
<?php include ("sponsor_header.php"); ?>
<table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height="315">
<tr>
<td width="11%" rowspan="2" height="43" valign="top"><img border="1" src="/sponsors/images/<?php echo $imgname[1]; ?>" width="115" height="92"></td>
<td width="45%" bgcolor="#003366" height="1">
<font face="Verdana" size="1" color="#FFFFFF">>> <? print("$FirstName<b>$LastName</b>"); ?> </font></td>
<td width="44%" bgcolor="#003366" height="1" align="right">
<font face="Verdana" size="1" color="#FFFFFF"><? print("$Vehicle"); ?></font></td>
</tr>
<tr>
<td width="89%" height="55" colspan="2" align="center">
<img border="1" src="/sponsors/images/<?php echo $imgname[2]; ?>" width="70" height="52">
<img border="1" src="/sponsors/images/<?php echo $imgname[3]; ?>" width="70" height="52">
<img border="1" src="/sponsors/images/<?php echo $imgname[4]; ?>" width="70" height="52">
<img border="1" src="/sponsors/images/<?php echo $imgname[5]; ?>" width="70" height="52">
<br><font face="Verdana" size="1"><a href="http://www.arospeed.net/sponsors/$FirstName$LastName.Images.php"><< CLICK HERE TO SEE MORE PHOTOS >></a></td>
</tr>
<tr>
<td width="100%" colspan="3" height="264"> <font face="Verdana" size="1"> <br>
<?
print("NAME: $FirstName $LastName<br>");
print("LOCATION: $Location<br>");
print("VEHICLE: $Vehicle<br>");
print("Q&A: $QA<br><br>");
print("MODIFICATIONS<br>");
print("EXTERIOR: $Exterior<br><br>");
print("SOUND/VIDEO: $ICE<br><br>");
print("INTERIOR: $Interior<br><br>");
print("WHEELS: $Wheels<br><br>");
print("SUSPENSION: $Suspension<br><br>");
print("BRAKES: $Brakes<br><br>");
print("SHOUT OUTS: $Shoutouts<br><br>");
print("FUTURE PLANS: $Future<br><br>");
?>
</font>
</td>
</tr>
<?php include ("sponsor_ftr.php"); ?>
ENDHTML;
$fo = fopen("sponsors/$FirstName$LastName.php", "w");
fwrite($fo, $page);
fclose($fo);
// THIS CREATES ANOTHER PAGE, IMAGE NAMES ALSO NOT RIGHT
$photos = <<<ENDHTML
<?php include ("sponsor_header.php"); ?>
<table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height="315">
<tr>
<td width="89%" height="55" colspan="2" align="center">
<img border="1" src="/sponsors/images/<?php echo $imgname[1]; ?>"><br>
<img border="1" src="/sponsors/images/<?php echo $imgname[2]; ?>"><br>
<img border="1" src="/sponsors/images/<?php echo $imgname[3]; ?>"><br>
<img border="1" src="/sponsors/images/<?php echo $imgname[4]; ?>"><br>
<img border="1" src="/sponsors/images/<?php echo $imgname[5]; ?>"><br>
<img border="1" src="/sponsors/images/<?php echo $imgname[6]; ?>"><br>
<img border="1" src="/sponsors/images/<?php echo $imgname[7]; ?>"><br>
<img border="1" src="/sponsors/images/<?php echo $imgname[8]; ?>"><br>
<img border="1" src="/sponsors/images/<?php echo $imgname[9]; ?>"><br>
<img border="1" src="/sponsors/images/<?php echo $imgname[10]; ?>">
</td>
</tr>
<?php include ("sponsor_ftr.php"); ?>
ENDHTML;
$fo = fopen("sponsors/$FirstName$LastName.Images.php", "w");
fwrite($fo, $photos);
fclose($fo);
include ("sponsors_ftr.php")
?>
include ("sponsors_ftr.php")
?>