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
Not Loading Function Into Div
I'm not sure whether to put this under the php forum or ajax forum but because I tink it's more of a
I apologise! It's a newbie to PHP feedback form problem!
Hi,
I am a total newbie to PHP. I am also a unemployed and need to get a job. So after 100% r
browse folder only
hi,
is there a way i can browse or get the directory or folder only and not the file?
i just w
PHP Session Issue
I'm having an issue with one section on my website dealing with sessions. Now I know that myself and
Error in query: Resource id #4??
hey guys, having a minor (i think) problem here that i havent been able to figure out. long story sh
Linkage between two scripts
Okay say I have this for a link in a script:
Code: <li><a href="#&q
php/mysql auto logout after 2 hour and reset password
Hi all,
This I hope will make sense. I've the following code which when a user logins in, cr
pagination - need help on passing of search query.
Hi, i have been trying for days but couldn't get this sorted out. Would like some professional help
code help - pagination
Hi all, I have this code, basically a user logs into my site and they get this page.
The pro
How can you detect variable string in a massive string?
Ok guys, i need some help with this one.
I am going to be getting a large string, like 10-20