HTML Image Tag / PHP Array - Help Me

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
toriboy
Forum Newbie
Posts: 5
Joined: Thu Jun 27, 2002 12:18 pm
Location: Fredericton, New Brunswick, Canada
Contact:

HTML Image Tag / PHP Array - Help Me

Post by toriboy »

Excuse me for being so stupid, I am not a programmer.
I got a problem with a script I use. I just need to know how to link (or image tag) something properly.
I use a php script to replicate html pages with a html form, the script replicates an html document that I put in it, then creates a directory and puts the html document (and any image the user may have uploaded via the form).

In the html document I put in the script (the template), what code do I put so that it will display the photo ? The html form has 6 photo uploads, I need to be able to put some code in the "template" in the places I want the photo to be.

The PHP Code Is
----------------------------

if (!file_exists($UserName)) {
mkdir("$UserName",0777);
chmod ($UserName,0777);
}elseif(!file_exists($AltUserName)) {
mkdir("$AltUserName",0777);
chmod ($AltUserName,0777);
$username = $AltUserName;
}else{ // error and back to main sign up page
$errors[] = "Both your chosen 'username and your alternative username are taken, please choose different ones.";
error_log("[PHPFormMail] Username already taken.");
$output .= "<p>Both your chosen 'username and your alternative username are already taken, please choose different ones. Please use the <a href=\"javascript: history.back();\">back</a> button to correct these errors.</p>\n";
output_html($output);
exit;
}
// does the directory exist ?
$DataPath = $username;
$DataPath .= "/";
$DataPath .= "index.html";
$myfile = fopen("$DataPath","w");

/********************************************/

$nPics = (count($pictures));

for($i = 0; $i < $nPics; $i++) {

if(stristr($HTTP_POST_FILES['pictures']['type'][$i], 'image/')){ // only accept picture files

if (is_uploaded_file($HTTP_POST_FILES['pictures']['tmp_name'][$i]))
copy($HTTP_POST_FILES['pictures']['tmp_name'][$i],
"$username/" . basename($HTTP_POST_FILES['pictures']['name'][$i]));
}
}
/********************************************/

$Body = "<html><head><title>Web Sites For Kwik Realtor</title><meta http-equiv=Content-Type content='text/html; charset=iso-8859-1'></head>
<body>
My HTML Template
</body></html>";

----------------------------

The html code for the form that makes the pages is below:
----------------------------

<form name="form1" method="post" enctype="multipart/form-data" action="replicate.php">

Name : <input type="text" name="realname" size="25" maxlength="100">
Email : <input type="text" name="email" size="25" maxlength="100">
City / Town: <input name="City" type="text" id="City" size="25" maxlength="100">
Username : <input type="text" name="username" size="20" maxlength="15">
Picture 1 : <input name="pictures[]" type="file" accept="image/gif,image/jpeg, image/png">
Picture 2 : <input name="pictures[]" type="file" accept="image/gif,image/jpeg, image/png">
Picture 3 : <input name="pictures[]" type="file" accept="image/gif,image/jpeg, image/png">
Picture 4 : <input name="pictures[]" type="file" accept="image/gif,image/jpeg, image/png">
Picture 5 : <input name="pictures[]" type="file" accept="image/gif,image/jpeg, image/png">
Picture 6 : <input name="pictures[]" type="file" accept="image/gif,image/jpeg, image/png">

</form>
-------------------------

The script works, It replicates the pages and uploaded the files to the directoy, it also put the name and email on the replicated page, I just have to put $Email. etc. where I want it too go.

The only problem I am having is , What do I need to put in the html code (the template) so each photo (by number) will display on the html page where I want it too, right now they don't display at all because I don't do not know what to put for an "image tag".

Please Help.

Thanks
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

Try putting these lines before the $Body line:

Code: Select all

$imagetags = "";
foreach( basename($HTTP_POST_FILES&#1111;'pictures']&#1111;'name'] as $picname )
  $imagetags .= "<img src="".$picname.""><br>\n";
Then when you need to put all of your images in the document, put a

Code: Select all

".$imagetags."
there.

Example:

Code: Select all

$Body = "<html><head><title>Web Sites For Kwik Realtor</title><meta http-equiv=Content-Type content='text/html; charset=iso-8859-1'></head> 
<body> 
My pictures:
<br><center>".$imagetags."</center>
</body></html>";
Hope this helps.
Post Reply