PHP4
I am uploading an image and writing its name to a database. The record number is not carrying over to the function and I don't know why. function form() holds the value but somewhere between the switch statement and function upload(), it looses it's value. Does anyone know what I've missed?
Here's the code:
<?php
//phpinfo();
$my_max_file_size = "102400"; # in bytes
$image_max_width = "300";
$image_max_height = "300";
$the_path = "images/";
$landnum = $landnum;
$registered_types = array(
"application/x-gzip-compressed"=> ".tar.gz, .tgz",
"application/x-zip-compressed" => ".zip",
"application/x-tar" => ".tar",
"text/plain" => ".html, .php, .txt, .inc (etc)",
"image/bmp" => ".bmp, .ico",
"image/gif" => ".gif",
"image/pjpeg" => ".jpg, .jpeg",
"image/jpeg" => ".jpg, .jpeg",
"application/x-shockwave-flash"=> ".swf",
"application/msword" => ".doc",
"application/vnd.ms-excel" => ".xls",
"application/octet-stream" => ".exe, .fla (etc)"
); # these are only a few examples, you can find many more!
$allowed_types = array("image/bmp","image/gif","image/pjpeg","image/jpeg");
-- fuction form()
function form($error=false) {
global $PHP_SELF,$my_max_file_size,$landnum;
if ($error) print $error . "<br><br>";
print "\n<form ENCTYPE=\"multipart/form-data\" action=\"" . $PHP_SELF . "\" method=\"post\">";
print "\n<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" . $my_max_file_size . "\">";
print "\n<INPUT TYPE=\"hidden\" name=\"task\" value=\"upload\">";
print "\n<P>Upload a file";
print "\n<BR>NOTE: Max file size is " . ($my_max_file_size / 1024) . "KB";
print "\n<br><INPUT NAME=\"the_file\" TYPE=\"file\" SIZE=\"35\"><br>";
print "\n<input type=\"submit\" Value=\"Upload\">";
print "\n</form>";
} # END form
#-- function upload()
function upload($the_file) {
global $the_path,$the_file_name,$landnum;
$landnum=$landnum;
//$error = validate_upload($the_file);
if ($error) { form($error); }
else
{ # cool, we can continue
if (!@copy($the_file, $the_path . "" . $the_file_name))
{ form("\n<b>Something did not take, check the path to and the permissions for the upload directory</b>");
}
else
{ //list_files();
form();
}
}
Header ("Location: edit.php?landnum=".$landnum."&fld_imagepath=".$the_file_name);
} # END upload
-- Start page
print "\n<head>\n<title>Upload example</title>\n</head>\n<body>";
echo "
landnum=".$landnum."<BR>
the_file=".$the_file.".<BR>
the_file_name=".$the_file_name.".<BR>
the_file_type=".$the_file_type.".<BR>
HTTP_POST_FILES['the_file']['name']=".$HTTP_POST_FILES['the_file']['name'].".<BR>
HTTP_POST_FILES['the_file']['type']=".$HTTP_POST_FILES['the_file']['type'].".<BR>
HTTP_POST_FILES['the_file']['size']=".$HTTP_POST_FILES['the_file']['size'].".<BR>
HTTP_POST_FILES['the_file']['tmp_name']=". $HTTP_POST_FILES['the_file']['tmp_name'].".<BR><BR>
";
//echo "x".$task."x";
switch(trim($task))
{ case "upload":
upload($the_file);
break;
default:
form(); }
print "\n</body>\n";
?>
=======
Thanks!