This is an old upload photo script I got from someone on this community. I have changed server recently to Apache, php is 5.2.0 and the mysql is 4.0. Problem is that this script doesn't work at all anymore. I don't even get an error message and it doesn't reach the functions "upload" or "validate" when I try uploading something. What could be wrong? :/
$my_max_file_size = "951200"; # in bytes
$image_max_width = "500";
$image_max_height = "600";
$the_path = '/newpictures/';
$registered_types = array(
"image/bmp" => ".bmp, .ico",
"image/gif" => ".gif",
"image/pjpeg" => ".jpg, .jpeg",
"image/jpeg" => ".jpg, .jpeg"
);
$allowed_types = array("image/bmp","image/gif","image/pjpeg","image/jpeg");
function form($error=false) {
global $PHP_SELF,$my_max_file_size;
if ($error) print $error . "<br><br>";
$photoname = $_GET['photoname'];
echo '<body link="#000000" vlink="#000000" alink="#000000">';
print "\n<form ENCTYPE=\"multipart/form-data\" action=\"http://www.xxxxxxx.com/uploadppicture.php\" 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>";
print "\n<BR>Largest Possible Filesize: " . ($my_max_file_size / 1024) . "KB (Maxstorlek (pixlar): ". $image_max_width ."X". $image_max_height .")";
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 validate_upload($the_file) {
global $my_max_file_size, $image_max_width, $image_max_height,$allowed_types,$the_file_type,$registered_types;
$start_error = "\n<b>Error:</b>\n<ul>";
if ($the_file == "none") { # do we even have a file?
$error .= "\n<li>You did not upload anything!</li>";
} else { # check if we are allowed to upload this file_type otherwise erase and delete everything
if (!in_array($the_file_type,$allowed_types)) {
$error .= "\n<li>The file that you uploaded was of a type that is not allowed, you are only allowed to upload files of the type:\n<ul>";
while ($type = current($allowed_types)) {
$error .= "\n<li>" . $registered_types[$type] . " (" . $type . ")</li>";
next($allowed_types);
}
$error .= "\n</ul>";
}
if (ereg("image",$the_file_type) && (in_array($the_file_type,$allowed_types))) {
$size = GetImageSize($the_file);
list($foo,$width,$bar,$height) = explode("\"",$size[3]);
if ($width > $image_max_width) {
$error .= "\n<li>Your image should be no wider than " . $image_max_width . " Pixels</li>";
}
if ($height > $image_max_height) {
$error .= "\n<li>Your image should be no higher than " . $image_max_height . " Pixels</li>";
}
}
if ($error) {
$error = $start_error . $error . "\n</ul>";
return $error;
} else {
return false;
}
}
} # END validate_upload
# --
function list_files() {
global $the_path;
$handle = dir($the_path);
echo '<strong><font size="1" face="Tahoma">';
print "\n<b>Uploaded Files:</b><br>";
while ($file = $handle->read()) {
if (($file != ".") && ($file != "..")) {
print "\n" . $file . "<br>";
print 'The File was Uploaded!';
}//End if
}//End while
print "<hr>";
}
# --
function upload($the_file) {
global $the_path,$the_file_name;
$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 barfed, check the path to and the permissions for the upload directory</b>");
echo $the_path;
echo $the_file_name;
} else {
move_uploaded_file($file['tmp_name'],$dir.$file['tmp_name']);
list_files();
form();
}
}
} # END upload
# --
############ Start page
echo '<strong><font size="2" face="Tahoma">';
print "<html>\n<head>\n<title>Upload example</title>\n</head>\n<body>";
switch($task) {
case 'upload':
// New name on picture
$the_path = '/newpictures/';
@mkdir($the_path, 0777);
upload($the_file);
$myarray = explode(".", $the_file_name);
$ext = $myarray[1];
$newname = $photoname . $ext;
rename($the_path . $the_file_name, $the_path . $newname);
break;
default:
form();
}
print "\n</body>\n</html>";