my code below will not echo out the image name that was chosen using the browse button.
any ideas?
thanks so much.
-randy
<? php
//// start the script
// THE ROOT OF THIS SERVER'S PUB HTML DIR
$public_html = "/home/asfcentral/www/np/";
$public_htmlw = "http://www.asfcentral.com/np/";
$uploaddir = "content/images/";
if ($REQUEST_METHOD == "POST") {
// SUBMITTED INFORMATION - use what you need
// temporary filename (pointer): $imgfile
// original filename : $imgfile_name
// size of uploaded file : $imgfile_size
// mime-type of uploaded file : $imgfile_type
$extStr = getFileExtension($imgfile_name);
// make the file extension all lower case
$extStr = strtolower($extStr);
echo "$imgfile_name";
echo "$extStr";
// If its not an image... tell the user and end the program
switch ($extStr) {
// valid file image extensions
case 'jpg':
break;
case 'jpeg':
break;
default:
echo "<p><font color=red>Invalid file type.</font><br>Please upload a valid image file of type: jpg or jpeg";
// reprint the form
displayForm();
// exit the program
exit();
}
$newfile = $uploaddir . "$imgfile_name";
// move file to proper directory to upload it to
// move back a directory to the main club directory
$move = chdir("..");
if (!file_exists($newfile)) {
// The file does exist
// print the club's directory name and remove white space
//$clubDir = trim(`pwd`);
//get rid of the directory part before it
//$clubDir = str_replace ("$public_html", "", $clubDir);
$filepath = $public_htmlw . $uploaddir . $imgfile_name;
if (!copy($imgfile,$newfile)) {
// if an error occurs the file could not
// be written, read or possibly does not exist
echo "Error Uploading File.
Please <a href=\"$SCRIPT_NAME\">try again</a> or email the webmaster.";
displayForm;
}
else { // upload was successfull!
?>
<table width="482" bordercolor="#222222" border="1" cellpadding="1" cellspacing="2" bgcolor="#777777">
<tr><td bgcolor="#999999">
<table width="480" border="0" cellpadding="8" cellspacing="4" bgcolor="#FFFFFF">
<tr><td bgcolor="#333388" width="100%" height="30"><center><font size="3" color="#ffffff"><b>SUCCESS!</b></font></center></td></tr>
<tr><td bgcolor="#ffffff" align="center"><font face="Comic Sans MS" size="2">
<p>Your file was uploaded successfully!<p>
<? echo "Your File: <b>$imgfile_name</b>";
echo "<p>View Uploaded File: <a href=\"$filepath\">$imgfile_name</a>";
?>
<p>Thank You!<br>
</FONT>
</td></tr>
<tr><td align="center">
</td></tr></table></td></tr></table>
<?
} //end else clause for success ful upload
} // end "if file not exists" clause
else {
//the file already exists.
echo "<font color=red>This file already Exists.</font> Please rename the file and try again.";
displayForm();
}
// delete temp file
unlink($imgfile);
} // end first if form was POSTed clause
// the form was not posted...
else {
// so lets display the html for uploading
displayForm();
}
// FUNCTIONS
function getFileExtension($str) {
echo "the str is : $str";
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
function displayForm() {
?>
</head>
<body bgcolor="#FFFFFF">
<h2>Upload an Image</H2>
<form action="<?echo $PHP_SELF; ?>" method="POST" enctype="multipart/form">
<input type="hidden" name="MAX_FILE_SIZE" value="1024000">
<input type="hidden" name="MAX_FILE_SIZE" value="1024000">
<p>Upload Image: <input type="file" name="imgfile"><br>
<font size="1">Click browse to upload a local file</font><br>
<br>
<input type="submit" value="Upload">
</form>
</body>
<?
return 0;
}
?>