<?php //functions for uploading
$file_types = array("application/x-gzip-compressed" => ".tar.gz .tgz",
"application/x-zip-compressed" => ".zip",
"application/x-tar" => ".tar",
"application/x-shockwave-flash" => ".swf",
"application/msword" => ".doc",
"application/vnd.ms-excel" => ".xls",
"application/octet-stream" => ".exe .fla",
"application/pdf" => ".pdf",
"video/quicktime" => ".mov .qt",
"video/mpeg" => ".mpg .mpeg",
"video/mp4" => ".mp4 .mpg4",
"audio/mp4" => ".mp4 .mpg4",
"audio/mp3" => ".mp3 .mpg3",
"text/plain" => ".htm .html .txt .inc. .php .php4 .pl .shmtl",
"image/bmp" => ".bmp .ico",
"image/gif" => ".gif",
"image/pjpeg" => ".jpg .jpeg",
"image/png" => ".png");
$allowed_types = array("image/bmp","image/gif","image/pjpeg","image/jpeg");
--
function form($error=false) {
global $PHP_SELF,$my_max_file_size;
$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 .= "<table width=\"70%\"><tr><td class=\"description\">";
$print .="\nUpload a file</td></tr>";
$print .="\n<tr><td><INPUT NAME=\"the_file\" TYPE=\"file\" SIZE=\"35\"></td></tr>";
$print .="\n<tr><td><select name=\"type\">";
$print .="\n<option value=\"news\">NEWS</option>";
$print .="\n<option value=\"gallery\">GALLERY</option>";
$print .="\n<option value=\"music\">MUSIC</option>";
$print .="\n</select></td></tr>";
$print .="\n<tr><td><input type=\"submit\" Value=\"Upload\"></td></tr>";
$print .="\n</form></table>";
if ($error)
{$form=$error.$print; }
else
{ $form = $print;}
return $form;
} # END form
function validate_upload($the_file) {
global $my_max_file_size, $image_max_width, $image_max_height,$allowed_types,$the_file_type,$file_types;
$start_error = "<div class=\"inform_error\">Error:<br />";
if ($the_file == "none") { # do we even have a file?
$error .= "You did not upload anything!<br />";
} else { # check if we are allowed to upload this file_type
if (!in_array($the_file_type,$allowed_types)) {
$error .= "you are only allowed to upload files of the type:";
while ($type = current($allowed_types)) {
$error .= $file_types[$type] . " (" . $type . ")";
next($allowed_types);
}
$error .= "<\div>";
}
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 .= "Your image should be no wider than " . $image_max_width . " Pixels<br />";
}
if ($height > $image_max_height) {
$error .= "Your image should be no higher than " . $image_max_height . " Pixels<br />";
}
}
if ($error) {
$error = $start_error . $error . "</div>";
return $error;
} else {
return false;
}
}
} # END validate_upload
--
function list_files() {
global $the_path;
$handle = dir($the_path);
$list = "<div class=\"inform\">Uploaded files:</div>";
while ($file = $handle->read()) {
if (($file != ".") && ($file != "..")) {
$list .= "<div class=\"inform\">" . $the_path . $file . "</div>";
}
}
return $list;
}
--
function upload($the_file) {
global $the_path,$the_file_name;
$error = validate_upload($the_file);
if ($error) {
$complete = form($error);
} else {
<--////--> This is where things goes wrong <--///-->
if (!copy($the_file, $the_path . "/" . $the_file_name)) {
$complete = form("<div class=\"inform_error\">problem when copying check it again</div>");
} else {
$complete = list_files().form();
}
}
return $complete;
}
function multiUpload($albumname,$total,$picture_num,$caption,$picture)
{
global $the_path,$picture_name;
if ($albumname!="" && $caption!="" && $picture!="")
{
$new_path = $the_path."\".$albumname;
if (!mkdir($new_path,0766))
{
$error = "<div class=\"inform_error\">could not create new directory!</div>";
}
for ($j=0;$j<$total;$j++)
{
$error = validate_upload($picture[$j]);
if ($error)
{
$error = "<div class=\"inform_error\">Could not validate file!!!</div>";
$complete_return = initForm($error,"Try to upload again");
}
if (!copy($picture[$j],$new_path."\\".$picture_name[$j]))
{
$error = "<div class=\"inform_error\">Error when copying file to folder!!!</div>";
$complete_return = initForm($error,"Try and upload again");
}
}
}
else
{
$complete_return = intiForm($error="<div class=\"inform_error\">Can not have empty field</div>","Try Again");
}
$complete_return = initForm($error=0,"Upload more pictures?");
return $complete_return;
}
function createPhotoForm($total)
{
$form = "<div class=\"pageinfo\">Get Ready to Upload Pictures</div>";
$form .= "<form name=\"photoupload\" method=\"post\" action=\"$PHP_SELF\" ENCTYPE=\"multipart/form-data\">";
$form .= "<input name=\"task\" type=\"hidden\" value=\"upload\">";
$form .= "<input name=\"total\" type=\"hidden\" value=\"$total\">";
$form .= "<table width=\"80%\"><tr><td class=\"description\">Album name</td>";
$form .= "<td><input name=\"albumname\" type=\"text\" size=\"50\" maxlength=\"50\"></td></tr>";
for ($i=0; $i<$total;$i++)
{
$form .= "<input name=\"picture_num[]\" type=\"hidden\" value=\"$i\" />";
$form .= "<tr><td class=\"description\">Caption</td><td>";
$form .= "<input name=\"caption[]\" type=\"text\" size=\"50\" maxlength=\"50\" /></td></tr>";
$form .= "<tr><td class=\"description\">Picture</td><td>";
$form .= "<input name=\"picture[]\" type=\"file\" /></td></tr>";
}
$form .= "<tr><td></td><td><input type=\"reset\" value=\"Clear Form\">";
$form .= "<input type=\"submit\" value=\"Sent Them\"></td><tr></table></form>";
return $form;
}
function initForm($error,$title)
{
$form = "<div class=\"pageinfo\">$title</div>";
$form .= "<form name=\"create\" method=\"post\" action=\"$PHP_SELF\">";
$form .= "<input name=\"task\" type=\"hidden\" value=\"make\" />";
$form .= "<table width=\"60%\"><tr><td>How Many Pictures?</td><td>";
$form .= "<input name=\"total\" type=\"text\" /></td><td>";
$form .= "<input name=\"CREATE TABLE\" type=\"submit\" /></td></tr></table></form>";
if ($error)
{
$big_form = $error.$form;
}
else
{
$big_form = $form;
}
return $big_form;
}
?>
Thanks a million for taking a look and I still have a few long nights ahead :-(