Ok im trying to upload an image and a .zip file to 2 different loactions at once aswell as put their links on my mysql database, heres my script, at the moment it displays nothing, does nothing and seriously needs fixing.
<?php
$username="my_username";
$password="my_password";
$database="my_database";
$font_name = ucfirst($_POST['font_name']);
$letter = $name{0};
$image = $_FILES['image']['name'];
$file = $_FILES['file']['name'];
$size = $_POST['size'];
$letterf1 = strtolower($_POST['font_name']);
$letterf2 = letterf1{0};
if(is_numeric($letter))
{$letter2="#";}
else { $letter2=$letter;}
if (empty($image)) {
$result = '<font color=FFFFFF>Please choose a image to upload!</font>';
$error++;
}
else {
$filename = stripslashes($image);
$extension = getextension($filename);
$extension = strtolower($extension);
if (($extension !== "png") && ($extension !== "gif")) {
$result = '<font color=FFFFFF>Unknown file extension, only .png and .gif images are allowed, please try again</font>';
$error++;
}
else {
$tmpFile = $_FILES['image']['tmp_name'];
$sizekb = filesize($tmpFile);
if ($sizekb > 2000000) {
$result = '<font color=FFFFFF>The image has exceeded the size limit, please try again</font>';
$error++;
}
else {
$imageName = '../images/fonts/' . $font_name . '.' . $extension;
$copy = copy($tmpFile, $imageName);
if (!$copy) {
$result = '<font color=FFFFFF>Image upload unsuccessful, please try again</font>';
$error++;
}
}
}
}
if ($error > 0) {
echo $result;
}
else {
if (empty($file)) {
$result = '<font color=FFFFFF>Please choose a file to upload!</font>';
$error++;
}
else {
$filename = stripslashes($file);
$extension = getextension($filename);
$extension = strtolower($extension);
if (($extension !== "zip")) {
$result = '<font color=FFFFFF>Unknown file extension, only .zip files are allowed, please try again</font>';
$error++;
}
else {
$tmpFile2 = $_FILES['file']['tmp_name'];
$sizekb = filesize($tmpFile2);
if ($sizekb2 > 2000000) {
$result = '<font color=FFFFFF>The file has exceeded the size limit, please try again</font>';
$error++;
}
else {
$imageName = '../downloads/fonts/' . $letterf2 . '/' . $font_name . '.' . $extension;
$copy = copy($tmpFile2, $fileName);
if (!$copy) {
$result = '<font color=FFFFFF>File upload unsuccessful, please try again</font>';
$error++;
}
}
}
}
if ($error > 0) {
echo $result;
}
else {
function ByteSize($bytes)
{
$size = $bytes / 1024;
if($size < 1024)
{
$size = number_format($size, 2);
$size .= ' KB';
}
else
{
if($size / 1024 < 1024)
{
$size = number_format($size / 1024, 2);
$size .= ' MB';
}
else if ($size / 1024 / 1024 < 1024)
{
$size = number_format($size / 1024 / 1024, 2);
$size .= ' GB';
}
}
return $size;
}
$size2 = ByteSize($sizekb2);
$con = mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$sql = "INSERT INTO `fonts` VALUES ('','$name','$letter2','$imageName','$fileName','$size2')";
$query = mysql_query($sql) or die('Error: ' . mysql_error());
mysql_close();
}
}
?>