Ok, I totally give up on thinking I have the brain power to figure this out on my own. Please help if you can! Here's my problem.
I have this form, that points to publishform.php. publishform.php uploads files that were submitted on the form, processes the text entered on the form, and then puts all that data on a brand new page. My problem is, I can't get the images that were uploaded to appear on the second new page that is created. I know I can print them out using a href=${imgname[1]}, a href=${imgname[2]} and so on, but if a user chooses to only upload 8 pictures and I have in the code a href=${imgname[1-10]} that leaves two red x's on the page that is outputted. I need something that will only output the a href= for the number of images that were uploaded. I hope that makes sense. My code is below and I've pointed out all the important places.
I know that this works if I put it where the script processes the uploads, but it doesn't work if I put it where I want the images to appear on the new page (I get a parse error saying a ) is needed):
if (file_exists($location)) {
print("<a href=$location target=_blank><img border=1 src=$location width=135 height=100></a>");
}
}
Please help!
Thanks,
Erica
<?php
include ("sponsors_header.php");
?>
<?
// ***THIS IS THE PART OF THE SCRIPT THAT PROCESSES THE UPLOADS***
$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 PART OF THE SCRIPT CREATES THE FIRST NEW PAGE WITH SOME OF THE IMAGES AND ALL TEXT FROM THE FORM***
$page = <<<ENDHTML
<?php include ("sponsor_header.php"); ?>
<body link="#000000" vlink="#000000" alink="#000000">
<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"><a href="/sponsors/images/${imgname[1]}" target="_blank"><img
border="1" src="/sponsors/images/${imgname[1]}" width="115" height="92"></a></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">
<a href="/sponsors/images/${imgname[2]}" target="_blank"><img border="1" src="/sponsors/images/${imgname[2]}" width="70"
height="52"></a>
<a href="/sponsors/images/${imgname[3]}" target="_blank"><img border="1" src="/sponsors/images/${imgname[3]}" width="70"
height="52"></a>
<a href="/sponsors/images/${imgname[4]}" target="_blank"><img border="1" src="/sponsors/images/${imgname[4]}" width="70"
height="52"></a>
<a href="/sponsors/images/${imgname[5]}" target="_blank"><img border="1" src="/sponsors/images/${imgname[5]}" width="70"
height="52"></a>
<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 PART CREATES THE SECOND NEW PAGE, AND THE PROBLEM***
$photos = <<<ENDHTML
<?php include ("sponsor_header.php"); ?>
<body link="#000000" vlink="#000000" alink="#000000">
<table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%"
height="315">
<tr>
<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="left">
// ***I WANT THE UPLOADED IMAGES TO SHOW UP HERE***
</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")
?>