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
Prevent PHP mail( ) from appending hostname to from address
Hey guys,
I want to be able to send texts to phones via email (since each phone has their own
(sub)screen resize modification doesn't work after ECC 6 EhP 4 installation
Hello,
We have previously extended the size of the custom data tab on PO transaction ME23
Must-Know Topics of PHP
Can you guys list the must-know topics of PHP. I am still a learner and I am trying to cover most of
gmdate() - want 1 hr before time
Hi,
I am using php gmdate().
Now I am entering all dates in my dbase using gmdate("Y-m-d
Facebook status update API
Hello,
So, I'm trying to create my first Facebook application with PHP.
Basic ideas fo
filesize problem
i use ubuntu 9.10 and i have mountet a folder from an windows
/mount/FOLDER
/mount/FOLDER/
How to ask a regex question?
Hi, I thought I'd share some of my insight after seeing too many bad questions that either get ignor
Quick Question about echo value
Hey guys, I'm trying to get something to show differently in one of my scripts. I'm trying to make
WELCOME SCREEN
first of all let me tell you what does my script do,
it´s a very simple query to show a e
FILTER_CALLBACK -- Files?
Hi All,
I'm using the php filter functions to validate my form data. For custom filters, I'm