rexolio2008
Technical User
I think this will be easy - I just don't know much about PHP to figure it out.
I paid someone to build this PHP upload script for me. Now I can't get in touch with them to fix it.
The script below successfully uploads an image that is over 400 pixels in height or width, but if the image is less than that, I get an error on line 45 that nwidth and nheight is undefined (I marked line 45 below).
Help??
CONFIG FILE:
UPLOAD SCRIPT:
I paid someone to build this PHP upload script for me. Now I can't get in touch with them to fix it.
The script below successfully uploads an image that is over 400 pixels in height or width, but if the image is less than that, I get an error on line 45 that nwidth and nheight is undefined (I marked line 45 below).
Help??
CONFIG FILE:
Code:
<?php
require_once 'functions.php';
$save_into_db = false;
$server_name = 'servername-here';
$user = 'dbusername-here';
$password = 'dbpassword-here';
$db_name = 'dbname-here';
if($save_into_db)
{
mssql_connect($server_name, $user, $password);
mssql_select_db($db_name);
init();
}
$file_path =dirname(__FILE__);
$upload_to = $file_path.'\\upload\\';
$num_files = 1;
$resize_to = 400;
$quality = 90;
?>
UPLOAD SCRIPT:
Code:
<?php
require_once 'config.php';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$error = array();
$message = array();
if($_FILES['image'])
{
if(is_array($_FILES['image']['name']) && count($_FILES['image']['name']))
{
foreach ($_FILES['image']['name'] as $key=>$name)
{
if(!$_FILES['image']['name'][$key])
continue;
if(file_exists($upload_to.$_FILES['image']['name'][$key]))
{
$error[] = 'File '.$_FILES['image']['name'][$key].' already exists';
continue;
}
preg_match('/\.([A-Za-z]+?)$/', $_FILES['image']['name'][$key], $matches);
$matches[1] = strtolower($matches[1]);
if($matches[1] == 'png' && function_exists('imagecreatefrompng') || $matches[1] == 'jpg' && function_exists('imagecreatefromjpeg') || $matches[1] == 'jpeg' && function_exists('imagecreatefromjpeg') || $matches[1] == 'gif' && function_exists('imagecreatefromgif')) {
list($owidth, $oheight) = getimagesize($_FILES['image']['tmp_name'][$key]);
if($matches[1] == 'png')
$original = imagecreatefrompng($_FILES['image']['tmp_name'][$key]);
if($matches[1] == 'jpg' || $matches[1] == 'jpeg')
$original = imagecreatefromjpeg($_FILES['image']['tmp_name'][$key]);
if($matches[1] == 'gif')
$original = imagecreatefromgif($_FILES['image']['tmp_name'][$key]);
if((($oheight>$resize_to) && ($oheight>$owidth)) || (($oheight>$resize_to) && ($oheight==$owidth))) {
$nheight = $resize_to;
$nwidth = $nheight / $oheight * $owidth;
$resized = imagecreatetruecolor($nwidth, $nheight);
}
elseif(($owidth>$resize_to) && ($owidth>$oheight)) {
$nwidth = $resize_to;
$nheight = $nwidth / $owidth * $oheight;
$resized = imagecreatetruecolor($nwidth, $nheight);
}
else
{
$resized = $original;
}
LINE 45 HERE imagecopyresampled($resized, $original, 0, 0, 0, 0, $nwidth, $nheight, $owidth, $oheight);
switch ($matches[1]) {
case 'png':
imagepng($resized,$upload_to.$_FILES['image']['name'][$key],$quality);
break;
case 'jpg':
imagejpeg($resized,$upload_to.$_FILES['image']['name'][$key],$quality);
break;
case 'gif':
imagegif($resized,$upload_to.$_FILES['image']['name'][$key],$quality);
break;
default:
$error[] = 'Unsupported image type for file: '.$_FILES['image']['name'][$key];
break;
}
if(file_exists($upload_to.$_FILES['image']['name'][$key]))
{
$message[] = 'File: '.$_FILES['image']['name'][$key].' successfully uploaded.';
if($save_into_db)
{
$data = array('name'=>$_FILES['image']['name'][$key],'size'=>$_FILES['image']['size'][$key],'type'=>$matches[1]);
save_file($data);
}
}
}
else
{
$error[] = 'Unsupported image type for file: '.$_FILES['image']['name'][$key];
}
}
//mssql_close();
}
else
{
$error[] = 'No images uploaded!';
}
} else
{
$error[] = 'No images recieved';
}
}
?>