I am not a programmer so if possible I need some pretty basic and detailed help on this. I am very very new to this.
I currently use a script to replicate html documents, it replicates the page by someone filling in an html form, the script put variables from the form into the new html page (EXAMPLE: if I put $Name in the template, the script would then put the "name" from the HTML form on the new html document).
The script has always worked fine because I never needed images just to replicates the page with some customization.
But now I need to put a few images on the html page (the user will upload the images via the form).
The script uloaded the files to the directory (wich is also taken from the html form) but I don't know how to make the "template" so the images show up on the new html page, the images are uploaded via a form so I do not know what the images names are. so I can't just put an image tag.
If I put $name in the template , then the name from the html form is put on the replicated page, I have 6 images on the form, how can I cange the code below, or the form , or whatever, so that I can put something like $image1 , $image2, etc on the tempalte and have it work.
Below is the php code and the html form code.
Please someone help. I am getting very frustrated!
Thank You In Advance.
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>
-------------------------
Still Need Help With Image Upload Script
Moderator: General Moderators
- RandomEngy
- Forum Contributor
- Posts: 173
- Joined: Wed Jun 26, 2002 3:24 pm
- Contact:
The problem is that you can't assume the user has uploaded all 6 pictures. Assume you did something like this:
Say the user uploads only 2 pictures. Then you'll get a lousy output like this:
Here is picture 1:
<picture here>
Here is picture 2:
<picture here>
Here is picture 3:
Here is picture 4:
Here is picture 5:
Here is picture 6:
Anyway, keep in mind that when you put in $image4 that it might not actually show up.
Put this code before the $Body line:
Then use $image1, $image2, etc in the template.
And next time, just make one post about it, and reply to it to bump it to the top if you MUST have an answer.
Code: Select all
Here is picture 1:<br>
$image1 <br>
Here is picture 2:<br>
$image2 <br>
...Here is picture 1:
<picture here>
Here is picture 2:
<picture here>
Here is picture 3:
Here is picture 4:
Here is picture 5:
Here is picture 6:
Anyway, keep in mind that when you put in $image4 that it might not actually show up.
Put this code before the $Body line:
Code: Select all
if( $HTTP_POST_FILESї'pictures']ї'size']ї0] != 0 )
$image1 = "<img src="".$HTTP_POST_FILESї'pictures']ї'name']ї0]."">";
if( $HTTP_POST_FILESї'pictures']ї'size']ї1] != 0 )
$image2 = "<img src="".$HTTP_POST_FILESї'pictures']ї'name']ї1]."">";
if( $HTTP_POST_FILESї'pictures']ї'size']ї2] != 0 )
$image3 = "<img src="".$HTTP_POST_FILESї'pictures']ї'name']ї2]."">";
if( $HTTP_POST_FILESї'pictures']ї'size']ї3] != 0 )
$image4 = "<img src="".$HTTP_POST_FILESї'pictures']ї'name']ї3]."">";
if( $HTTP_POST_FILESї'pictures']ї'size']ї4] != 0 )
$image5 = "<img src="".$HTTP_POST_FILESї'pictures']ї'name']ї4]."">";
if( $HTTP_POST_FILESї'pictures']ї'size']ї5] != 0 )
$image6 = "<img src="".$HTTP_POST_FILESї'pictures']ї'name']ї5]."">";And next time, just make one post about it, and reply to it to bump it to the top if you MUST have an answer.
-
toriboy
- Forum Newbie
- Posts: 5
- Joined: Thu Jun 27, 2002 12:18 pm
- Location: Fredericton, New Brunswick, Canada
- Contact:
Thanks RandomEngy
Thank you very much for the reply, I will try what you said right now,
Sorry about the multible posts.
Sorry about the multible posts.