 |

07-22-2004, 11:23 AM
|
|
WebProWorld Member
|
|
Join Date: Jul 2004
Location: 03301
Posts: 29
|
|
PHP question
Hello
I have this PHP upload script and would like to add a couple additional functions to the success page. I know nothing about php beyond recognizing it.
Here is the PHP success page:
Code:
<?
###########################################################
# File Uploading Script #
# By Kieren Searle #
# 02/01/2003 #
# www.ukdragon.com #
###########################################################
##### Edit These Values #####
//ALLOWED FILE TYPES - GO WITH THE PATERN
$ext = array(".tif", ".zip", ".gif", ".jpg", ".bmp");
//FULL PATH TO UPLOAD FOLDER
$ufolder = "/home/elsowceo/public_html/customer/uploads/";
//URL TO FOLDER WHERE FILES WILL BE STORED
$url = "http://www.elsographics.com/customer/uploads/";
//TITLE OF WEBSITE IF UPLOAD IS SUCCESSFUL
$title = "Elso Graphics - Upload successful";
//NORMAL TITLE OF WEBPAGE (BEFORE UPLOAD)
$ntitle = "Elso Graphics File Uploader";
//THE MAX FILE SIZE IN BYTES (TIMES BYTES BY 1024 TO GET KB AND TIMES KB BY 1024 AGAIN TO GET MB)
$max_file_size = "4194304";
//WHEN LISTING FILE, DON'T INCLUDE THESE
$not_include = array(".", "..", "index.php", "show_upload.php", "do_upload.php", "index.html");
##### Don't Edit Any More Without Knowlege of PHP #####
//stop file hear if it is called by other page, we may just want the above values.
if($called)
{
return;
}
//make sure file name is lower case.
$_FILES['img1']['name'] = strtolower($_FILES['img1']['name']);
//get rid of spaces
$_FILES['img1']['name'] = str_replace(' ', '_', $_FILES['img1']['name']);
//get rid of '$'
$_FILES['img1']['name'] = str_replace('$', '_', $_FILES['img1']['name']);
//take the file name, and then get all the stuff after the last '.' (the file extension)
$file_name = $_FILES['img1']['name'];
$file_name = strrchr($file_name, ".");
//make sure file type is supported
if(!in_array($file_name,$ext))
{
$error = "File type not supported. Supported files are ";
foreach( $ext as $exts ){
$error .= "$exts ";
}
die ("$error");
}
//make sure file name isn't taken
$at = "$ufolder".$_FILES['img1']['name']."";
if(file_exists($at))
{
die ("File name already taken, please re-name and try again.");
}
//make sure file isn't too large
$file_size = $_FILES['img1']['size'];
if($file_size > $max_file_size)
{
die ("File is too large. Max size is 4MB. You could try zipping it up :)");
}
//copy file across
if ($_FILES['img1'] != "") {
copy($_FILES['img1']['tmp_name'], "$ufolder".$_FILES['img1']['name'])
or die("Couldn't copy the file!");
} else {
die("No input file specified");
}
?>
<html>
<head>
<title><?PHP print"$title"; ?></title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function sendValue(s){
var selvalue = document.yourform.msg.value;
window.opener.document.getElementById('image1').value = selvalue;
window.opener.document.getElementById('image2a').value = selvalue;
window.opener.document.getElementById('image3a').value = selvalue;
window.opener.document.getElementById('image4a').value = selvalue;
var selvalue1 = document.yourform.msg1.value;
window.opener.document.getElementById('first_image').src = selvalue1;
window.opener.document.getElementById('image1a').value = selvalue1;
window.opener.document.getElementById('image2').value = selvalue1;
window.opener.document.getElementById('image3').value = selvalue1;
window.opener.document.getElementById('image4').value = selvalue1;
window.close();
}
// End -->
</script><SCRIPT language="JavaScript" type="text/JavaScript">
<!--
function click(e){if (document.all) if (event.button == 2) return false;if
(document.layers) if (e.which == 3) return false;}
function click2(){event.returnValue=false;return false;}if (document.layers)
document.captureEvents(Event.MOUSEDOWN);document.onmousedown=click;document.oncontextmenu=click2;
// --> </SCRIPT><body background="../../../assets/tile.jpg" marginheight=10 marginwidth=10>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="27" height="12" nowrap>[img]../../../popups/tl1.gif[/img]</td>
<td width="100%" height="12" background="../../../popups/t_fill.jpg"></td>
<td width="27"><div align="right">[img]../../../popups/tr1.gif[/img]</div>
</td>
</tr>
<tr>
<td colspan="3"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="17" valign="top" background="../../../popups/l_fill.jpg">[img]../../../popups/tl2.jpg[/img]</td>
<td rowspan="3" valign="top" background="../../../assets/fill.jpg">
<?PHP
//get the file type and chop of the bit after the '/' to easily see if the file type is an image
$file_type = $_FILES['img1']['type'];
$rfile_type = strstr($file_type, '/');
$file_type = str_replace($rfile_type, "", $file_type);
//let them know everything
print "<font face=\"Arial\" size=\"2\">";
print "\"".$_FILES['img1']['name']."\" was uploaded successfully.";
if($file_type == "image")
{
print "
";
Print "<TABLE><TR><TD>";
print "<img src=\"$url".$_FILES['img1']['name']."\" width=150>";
} else {
print "
<TABLE><TR><TD>";
}
print "</TD><TD>";
print "<form name=yourform>";
print "<input type=hidden name=\"msg1\" value=$url".$_FILES['img1']['name'].">";
print "<input type=hidden name=\"msg\" value=".$_FILES['img1']['name'].">";
print "<input type=button value=\"Click to Confirm\" onClick='sendValue(this.form.selectmenu);'>";
print "</form>";
print "</TD></TR></TABLE>";
print "
";
print "This file is ". round(($file_size/1024), 2) ."KB";
print "</font>";
?>
</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"></div> <div align="center">[img]../../../assets/upload.gif[/img]</div>
</td>
</tr>
</table>
</td>
<td width="17" valign="top" background="../../../popups/r_fill.jpg">[img]../../../popups/tr2.jpg[/img]</td>
</tr>
<tr>
<td background="../../../popups/l_fill.jpg"></td>
<td background="../../../popups/r_fill.jpg"></td>
</tr>
<tr>
<td width="17" valign="bottom" background="../../../popups/l_fill.jpg">[img]../../../popups/bl2.jpg[/img]</td>
<td width="17" valign="bottom" background="../../../popups/r_fill.jpg">[img]../../../popups/br2.jpg[/img]</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="12">[img]../../../popups/bl1.gif[/img]</td>
<td height="12" background="../../../popups/b_fill.jpg">[img]../../../popups/b_fill.jpg[/img]</td>
<td height="12">[img]../../../popups/br1.gif[/img]</td>
</tr>
</table>
</body>
</html>
Basically this page is a popup window and will pass both the uploaded file name and the url back to the origination page. I am using the uploaded file name to also display the image. What I would also like it to do is in the event someone uploads a TIF (or other non browser supported file); I would like it to insert a default image to get passed to the opening page while still passing the uploaded file name to the other appropriate fields in the opening page.
Second objective is I would like it to send me an e-mail whenever a successful upload occurs.
Thanks
Nelson
|

07-22-2004, 12:36 PM
|
|
WebProWorld 1,000+ Club
|
|
Join Date: Sep 2003
Location: Texas
Posts: 1,283
|
|
Here you go...
Make sure you have a backup copy, then...
At the top of the script you see:
Code:
//ALLOWED FILE TYPES - GO WITH THE PATERN
$ext = array(".tif", ".zip", ".gif", ".jpg", ".bmp");
This is where you modify what file types you accept. Add the extensions you wish to allow, remove those you don't want allowed.
Change:
Code:
//copy file across
if ($_FILES['img1'] != "") {
copy($_FILES['img1']['tmp_name'], "$ufolder".$_FILES['img1']['name'])
or die("Couldn't copy the file!");
to:
Code:
//copy file across
if ($_FILES['img1'] != "") {
copy($_FILES['img1']['tmp_name'], "$ufolder".$_FILES['img1']['name'])
or die("Couldn't copy the file!");
$msg = "Change this text to whatever you want your email to you to say\n\n";
$to = "your@email-address.com";
$subject = "Whatever email subject you want";
$mailheaders = "From: Your Website Address\n";
$mailheaders .= "Reply-To: Whatever\n\n";
mail($to, $subject, $msg, $mailheaders);
Anyway, I think that will work, I haven't tested it.
|

07-22-2004, 01:01 PM
|
|
WebProWorld Member
|
|
Join Date: Jul 2004
Location: 03301
Posts: 29
|
|
I can follow this
Flood6
Thank you, I can follow your post and can see that this will address sending me a notice with each upload.
Number 2 question from my original post, I think was missunderstood. I realize I can set the ext. I accept a wide variety of image formats for printing. When someone uploads a jpg, bmp or gif, I have my shopping cart set to display my customer's upload all the way through checkout. But if someone upload a ZIP or TIF (more to come) these can not be displayed in the browser, so I would like to have the script call a default jpg for display purpose whenever a zip or tif is uploaded.
You will see the msg & msg1 fields I am using in the JS on this page to bring both the filename only and the full url back to the opening page.
Thank you
Nelson
|

07-22-2004, 01:48 PM
|
|
WebProWorld 1,000+ Club
|
|
Join Date: Sep 2003
Location: Texas
Posts: 1,283
|
|
My Bad
Bah...you were clear, I just didn't read the whole question, lol.
OK, remember to backup and try this:
Change:
Code:
print "
<TABLE><TR><TD>";
to
Code:
print "
";
Print "<TABLE><TR><TD>";
print "<img src=\"path-to-alt-image/altimage.jpg\">";
Try that. I code by trial and error, so not having a full working version for me to play with may produce unexpected results, so let me know if it doesn't work. I have another idea that will work if this method doesn't.
|

07-22-2004, 02:56 PM
|
|
WebProWorld Member
|
|
Join Date: Jul 2004
Location: 03301
Posts: 29
|
|
Mail works, default image dosen't
Ok, I am going to try and sound smart:-) From looking through this php I can see that:
Code:
if($file_type == "image")
{
print "
";
Print "<TABLE><TR><TD>";
print "<img src=\"$url".$_FILES['img1']['name']."\" width=150>";
} else {
print "
";
Print "<TABLE><TR><TD>";
print "<img src=\"http://www.elsographics.com/assets/upload_done.gif\">";
}
Through this i can understand the words "if" & "Else". Apparently it is seeing the tif as an image, because it's not making it to the "else" and trying to display the tif as an image.
Now I don't know just how the data flows but there is a second spot that this default image url needs to be written (if non displayable).
I have these hidden fields on this page:
[code
print "<form name=yourform>";
print "<input type=hidden name=\"msg\" value=$url".$_FILES['img1']['name'].">";
print "<input type=hidden name=\"msg1\" value=".$_FILES['img1']['name'].">";
print "<input type=button value=\"Click to Confirm\" onClick='sendValue(this.form.selectmenu);'>";
print "</form>";
[/code]
Feild name "msg" would need this default image if a non displayable image is uploaded.
Field name "msg1" if the actual filename uploaded (regardless of file type)
Thank you for your help
Nelson
|

07-22-2004, 08:58 PM
|
|
WebProWorld Member
|
|
Join Date: Jul 2004
Location: 03301
Posts: 29
|
|
This was simple or I lucked out
Flood6
Through your examples and a bunch of trial and error, I got this to do what I need:-)
I don't know if it's right or not, but it works (even in Netscape)
Thanks
Nelson / www.elsographics.com/
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|