Add "width" check when upload
Posted on
16th Feb 2014 07:03 pm by
admin
Hi!
Can someone add a function that is checking if picture witdh is bigger then 800px whwn uploading, then echo "image oversized" to the code below?
Code: <?php
###/ VARIABLES - CHANGE ACCORDINGLY
define("VAR_BASE_DIRECTORY","/home/web30217/domains/mysite.com/public_html/");
define("VAR_UPLOAD_FOLDER","upload/");
define("VAR_UPLOAD_DIRECTORY",VAR_BASE_DIRECTORY.VAR_UPLOAD_FOLDER);
define("VAR_UPLOAD_FIELDS",1);
define("VAR_FILENAME_KEEP",0);
##/ Function that displays forms and is called by default
function defaultForm()
{
echo "<form method="post" enctype="multipart/form-data">n";
for($i=0; $i < VAR_UPLOAD_FIELDS; $i++)
{
echo "<input name="file[]" type="file" id="file[]" /><br />n";
echo "<div style="height:2px"></div>";
}
echo "<div style="height:1px"></div>";
echo "<br /><input name="Submit" type="image" src="/images/upload.jpg" value="Ladda upp">n";
echo "<input name="filter" type="hidden" value="processForm">n";
echo "</form>n";
return;
}
#/ End of defaultForm
##/ Function that displays forms and is called by default
function processForm()
{
for($i=0; $i < VAR_UPLOAD_FIELDS; $i++)
{
echo "";
if(!empty($_FILES[file][size][$i]))
{
if(VAR_FILENAME_KEEP==1)
{
##/ File maintaining upload name
$fileName = $_FILES[file][name][$i];
}
else
{
##/ Filename randomized
$fileName = rand(10000,400000).rand(1,10).'.' . substr($_FILES[file][name][$i], -3);
}
##/ Creating reference address
$newLocation = VAR_UPLOAD_DIRECTORY.$fileName;
if(!copy($_FILES[file][tmp_name][$i],$newLocation))
{
echo "<b>Failed - ".$_FILES[file][name][$i]." would not copy to ".$newLocation."</b> (Check your upload directory and permissions)";
}
else
{
###/ SUCCESS /###
#/ Stripping of VAR_BASE_DIRECTORY for better viewing and linking
$urlShow = str_replace(VAR_BASE_DIRECTORY,'',$newLocation);
echo "&#91;img&#93;http://mysite.com/$urlShow&#91;&#47;img&#93;";
}
}
else
{
echo "";
}
echo "<br />";
}
return;
}
#/ End of processForm
##/ This object handles which function the application should call
switch($_POST[filter]) {
case "processForm":
processForm();
break;
default:
defaultForm();
break;
}
#/ End of Handling
?>
No comments posted yet
Your Answer:
Login to answer
108
5
Other forums
Data Function is Its Not working IN IE8
This is my first time to use formums. I hope i can get solution for this problem.
view plaincopy to
FROM_UNIXTIME($phpdate);
Hello,
I tried to use this :
$date = FROM_UNIXTIME($phpdate);
ANd I was t
frames get header location..
i have two frames, one top, one bottom. how do i do a form on the bottom frame that gives me the ur
All possible combinations of String in PL/SQL
Hi All,
Could you please explain the logic of getting all possible combinations of String
utf8_general_ci error ??
I have all kinds of data to be inserted in database table
//I am getting this error
Yo
Phase Error I can't seem to find :(`
Hey guys, I can seem to find my phase error on this. I am getting this error
[error]
Pars
MYSQL INSERT ID NOT WORKING
Code: $id = mysql_insert_id();
header("Location: ./?view=$id");
Why $id pulling blan
phph within href not showing php if change ? to &
Code: [Select]<a href="<?php echo $puser; ?>?m=<?php=(($m-1)&l
OOP help
okay so i have a class im making it has everything setup i just need to randomize the 2 variables an
asp authentication problem
Hello all,
I want to use the asp authentication (from asp.net configuration) in my web site. there