Here is a bit more of it (it is a really long file) :-)
//function uploadimage($filename, $the_file, $filetype, $newname, $fieldname, $thx, $thy)
}
}
}
if($updatefile && $fileid)
{
$result = mysql_query("SELECT * FROM files WHERE member_id=\"$MEMBER_ID\" AND id=\"$fileid\"",$SESS_DBH);
$myrow = mysql_fetch_array($result);
$insert_id=$myrow[id];
$sql="UPDATE files SET title='$title', client='$client', description='$description', url='$url', for_sale='$for_sale', price='$price', sale_description='$sale_description', keywords='$keywords', image_type='$image_type', shipping_required='$shipping_required' WHERE member_id=\"$MEMBER_ID\" AND id=\"$fileid\"";
$result = mysql_query($sql,$SESS_DBH);
if(is_uploaded_file($the_file))
{
$direxists=file_exists('files/'.$MEMBER_ID);
//if($MEMBER_ACCESS==7 && !$direxists)
if(!$direxists)
{
mkdir("files/$MEMBER_ID",0775);
}
//echo $the_file_name;
$allowed_types = array("image/gif", "image/bmp", "image/png","image/x-png", "image/pjpeg","image/jpeg","application/x-shockwave-flash","application/msword","application/vnd.ms-excel","application/x-zip-compressed","application/pdf", "application/octet-stream", "video/mpeg");
if (!in_array($the_file_type, $allowed_types))
{
//echo "$the_file_type";
$msg= "Sample file $the_file_name was not uploaded as it is not of the valid type. Only .gif, .bmp, .png, .jpg, .jpeg, .swf, .doc, .zip and .pdf files can be uploaded<BR>";
}
elseif(file_exists("files/$MEMBER_ID/$the_file_name") && $the_file_name!="$myrow[name]")
{
$msg="This file already exists, the file was not uploaded. To upload this file you must delete the provious file.<BR>";
}
else
{
//echo "files/$MEMBER_ID/$the_file_name";
if(file_exists($the_path.$myrow[name]))
{unlink($the_path.$myrow[name]);}
if(uploadimage($the_file_name, $the_file, $the_file_type))
{
$the_file_name=str_replace (" ", "", $the_file_name);
$sql="UPDATE files SET name='$the_file_name' WHERE member_id=\"$MEMBER_ID\" AND id=\"$fileid\"";
$result = mysql_query($sql,$SESS_DBH);
$msg.= "File has been update.<BR>";
}
}
}
if(is_uploaded_file($the_file_tn))
{
$direxists=file_exists('files/'.$MEMBER_ID);
//if($MEMBER_ACCESS==7 && !$direxists)
if(!$direxists)
{
mkdir("files/$MEMBER_ID",0775);
}
//echo $the_file_name;
$allowed_types = array("image/gif", "image/bmp", "image/png","image/x-png", "image/pjpeg","image/jpeg","application/x-shockwave-flash","application/msword","application/vnd.ms-excel","application/x-zip-compressed","application/pdf", "application/octet-stream", "video/mpeg");
$imagearray=getimagesize($the_file_tn);
if(!($imagearray[0]==80 && $imagearray[1]=80) )
{
$msg.= "Thumbnail uploaded is not a 80X80 pixel file and hence was not updated.<BR>";
}
elseif (!in_array($the_file_tn_type, $allowed_types))
{
//echo "$the_file_type";
$msg.= "Sample file $the_file_name was not uploaded as it is not of the valid type. Only .gif, .bmp, .png, .jpg, .jpeg, .swf, .doc, .zip and .pdf files can be uploaded<BR>";
}
else
{
//determining the new name of TN
$ext = strtolower(strrchr($the_file_tn_name, "."));
$filename="t".$insert_id."$ext";
if(is_uploaded_file($the_file_tn))
{
if(uploadimage($filename, $the_file_tn, $the_file_tn_type)) //uploading the thumbnail
{
$sql="UPDATE files SET tname='$filename' WHERE id='$insert_id' AND member_id='$MEMBER_ID'";
$result = mysql_query($sql,$SESS_DBH);
$msg.= "File thumbnail has been updated.<BR>";
}
}
}
}
$view=1;
}
if($sendup)
{
$result = mysql_query("SELECT * FROM files WHERE member_id=\"$MEMBER_ID\" AND id=\"$sendup\"",$SESS_DBH);
$myrow = mysql_fetch_array($result);
if($myrow[serial]!=1)
{
$result = mysql_query("UPDATE files SET serial=serial+1 WHERE member_id=\"$MEMBER_ID\" AND serial=".($myrow[serial]-1),$SESS_DBH);
$result = mysql_query("UPDATE files SET serial=serial-1 WHERE member_id=\"$MEMBER_ID\" AND id=$myrow[id]",$SESS_DBH);
}
//do a sort, not necessary for we still do it cause sometimes we get double serial
$serial=1;
$result = mysql_query("SELECT * FROM files WHERE member_id=\"$MEMBER_ID\" ORDER BY serial ASC",$SESS_DBH);
while($myrow = mysql_fetch_array($result))
{
$result2 = mysql_query("UPDATE files SET serial=$serial WHERE member_id=\"$MEMBER_ID\" AND id=$myrow[id]",$SESS_DBH);
$serial++;
}
$view=1;
}
if($senddown)
{
$result = mysql_query("SELECT * FROM files WHERE member_id=\"$MEMBER_ID\" AND id=\"$senddown\"",$SESS_DBH);
$myrow = mysql_fetch_array($result);
$result = mysql_query("SELECT * FROM files WHERE member_id=\"$MEMBER_ID\" AND serial>$myrow[serial]",$SESS_DBH);
if(mysql_affected_rows())
{
$result = mysql_query("UPDATE files SET serial=serial-1 WHERE member_id=\"$MEMBER_ID\" AND serial=".($myrow[serial]+1),$SESS_DBH);
$result = mysql_query("UPDATE files SET serial=serial+1 WHERE member_id=\"$MEMBER_ID\" AND id=$myrow[id]",$SESS_DBH);
}
//do a sort, not necessary for we still do it cause sometimes we get double serial
$serial=1;
$result = mysql_query("SELECT * FROM files WHERE member_id=\"$MEMBER_ID\" ORDER BY serial ASC",$SESS_DBH);
while($myrow = mysql_fetch_array($result))
{
$result2 = mysql_query("UPDATE files SET serial=$serial WHERE member_id=\"$MEMBER_ID\" AND id=$myrow[id]",$SESS_DBH);
$serial++;
}
$view=1;
}
if($delete)
{
$result = mysql_query("SELECT * FROM files WHERE member_id=\"$MEMBER_ID\" AND id=\"$delete\"",$SESS_DBH);
$myrow = mysql_fetch_array($result);
if(file_exists($the_path.$myrow[name]))
{unlink($the_path.$myrow[name]);}
if(file_exists($the_path.$myrow[tname]))
{unlink($the_path.$myrow[tname]);}
$sql="DELETE FROM files WHERE member_id=\"$MEMBER_ID\" AND id=\"$delete\"";
//echo $sql;
$result = mysql_query($sql,$SESS_DBH);
if(mysql_affected_rows())
{$msg= "File has been deleted.";}
else
{$msg="File was not deleted.";}
$result = mysql_query("UPDATE files SET serial=serial-1 WHERE member_id=\"$MEMBER_ID\" AND serial>$myrow[serial]",$SESS_DBH);
$view=1;
}
?>