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
?>
108
5
Other php-forum
Help with echo()
I'm having some problems with this code:
Code: echo '
<A HREF="jav
Is there a more efficient way to code this than what I have?
I have three associative arrays.
$combinedSettings
$userSettings
$defaultSettings
some query on multilingual website
Hi all,
Which is the simplest and easiest method to make a website multilingual,
is it put
upload only text files
hi guys i want to upload only text like like (pdf,note pad and ofiice files) so can any one please t
square instead of number
Hello
I do not know why but this code seems to work fine only in my xampp local insallation but n
PHP Session Issue
I'm having an issue with one section on my website dealing with sessions. Now I know that myself and
URL Rewrite issue
Im created a series of Rewrites and on page checks to make sure the correct url is being called. But
Sort a two dimensional array.
Hi. I've set up a two dimensional array that reads as follows:
Code: $modifiedData = array(
What's wrong with my code
sobbing for many days, still don't know why please Help. Why my page isn't posted correctly. In a
cURL Sending File as Post
This is a bit complicated, I'm just hoping someone else has run into this and knows how to do it a d