help with image upload code


Posted on 16th Feb 2014 07:03 pm by admin

Hello,

right now this code I have resizes images and then places them into the uploads folder is there a way to make this code upload the orignal file sizes into uploads and make it put the smaller version in a folder called thumbs
here is the upload.php code:

<?php

include('config.php');



function uploadImage($fileName, $maxSize, $maxW, $fullPath, $relPath, $colorR, $colorG, $colorB, $maxH = null){

$folder = $relPath;

$maxlimit = $maxSize;

$allowed_ext = "jpg,jpeg,gif,png,bmp";

$match = "";

$filesize = $_FILES[$fileName]['size'];

if($filesize > 0){

$filename = strtolower($_FILES[$fileName]['name']);

$filename = preg_replace('/s/', '_', $filename);

if($filesize < 1){

$errorList[] = "File size is empty.";

}

if($filesize > $maxlimit){

$errorList[] = "File size is too big.";

}

if(count($errorList)<1){

$file_ext = preg_split("/./",$filename);

$allowed_ext = preg_split("/,/",$allowed_ext);

foreach($allowed_ext as $ext){

if($ext==end($file_ext)){

$match = "1"; // File is allowed

$NUM = time();

$front_name = substr($file_ext[0], 0, 15);

$newfilename = $front_name."_".$NUM.".".end($file_ext);

$filetype = end($file_ext);

$save = $folder.$newfilename;

if(!file_exists($save)){

list($width_orig, $height_orig) = getimagesize($_FILES[$fileName]['tmp_name']);

if($maxH == null){

if($width_orig < $maxW){

$fwidth = $width_orig;

}else{

$fwidth = $maxW;

}

$ratio_orig = $width_orig/$height_orig;

$fheight = $fwidth/$ratio_orig;



$blank_height = $fheight;

$top_offset = 0;



}else{

if($width_orig <= $maxW && $height_orig <= $maxH){

$fheight = $height_orig;

$fwidth = $width_orig;

}else{

if($width_orig > $maxW){

$ratio = ($width_orig / $maxW);

$fwidth = $maxW;

$fheight = ($height_orig / $ratio);

if($fheight > $maxH){

$ratio = ($fheight / $maxH);

$fheight = $maxH;

$fwidth = ($fwidth / $ratio);

}

}

if($height_orig > $maxH){

$ratio = ($height_orig / $maxH);

$fheight = $maxH;

$fwidth = ($width_orig / $ratio);

if($fwidth > $maxW){

$ratio = ($fwidth / $maxW);

$fwidth = $maxW;

$fheight = ($fheight / $ratio);

}

}

}

if($fheight == 0 || $fwidth == 0 || $height_orig == 0 || $width_orig == 0){

die("FATAL ERROR REPORT ERROR CODE [add-pic-line-67-orig] to <a href='http://www.atwebresults.com'>AT WEB RESULTS</a>");

}

if($fheight < 45){

$blank_height = 45;

$top_offset = round(($blank_height - $fheight)/2);

}else{

$blank_height = $fheight;

}

}

$image_p = imagecreatetruecolor($fwidth, $blank_height);

$white = imagecolorallocate($image_p, $colorR, $colorG

No comments posted yet

Your Answer:

Login to answer
203 Like 32 Dislike
Previous forums Next forums
Other forums

generating all possible random letters
hi'

how can i randomize the letters a,b,c,d,e all possible ways, and i want to print the res

Sufficient protection from bad input?
I am writing a simple script to let people upload 'pages' of their own content, be it simply a few b

Count of reciepients in php mailer
How can i sent a mail to large no of reciepients say 10,00,00 Using PHP MAILER

Required to login help
I'm trying to set up my site so users have to be logged into the forum to access the site.I've been

PL/SQL: ORA-00947: not enough values error message
Hi all i am getting Error(25,63): PL/SQL: ORA-00947: not enough values error message when executing

How to show the difference between two data field in a database with php.
Hello php gurus,

how r u all... i'm not so well facing a typical problem please help me...<

Taking an HTML form and a PHP program and making it into one working file.
Hello,

So I would like to display everything INSIDE a specific directory. In other words, I

Links not updating
I'm trying to fuel a simple navigation system for a news section. It works fine when it comes to ret

Registration
ok so i have a site where people can register and login which works now thanks to someone on here th

private constructor
Hello,

Can we create a constructor as private? If yes, what is the use of it? If no, why can'

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash