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 "&#38;#91;img&#38;#93;http://mysite.com/$urlShow&#38;#91;&#38;#47;img&#38;#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 Like 5 Dislike
Previous forums Next forums
Other forums

Form File Upload
I've read through tons of resources and tutorials and as far as I can tell, my code is accurate, but

Regular expression tips or resources
Hello! I'm having some issues implementing the appropriate regex patter to eliminate unwanted charac

PHP SUBMIT
Code: <input name="doLogin" type="image" src="images/loginsubmit.jpg

unexpected T_VARIABLE error
Hey all! I'm getting an unexpected T_VARIABLE with the following function:

function getHighes

a function to check directory depth
I'm working on a php script to upload files in to a set directory.
the user can select to upload

PEAR in appliactiond development
When I was picking up PHP I went from procedural programming, fairly quickly into OOP, then after wr

Problem executing bash script using shell_exec
Hi there,
I created a bash script file using following code to convert doc documents to pdf using

Storing Values taken from a DB...
Using this code it will generate a short list from my database

<?php
mysql_connect

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

Get word number x from string?
How can I use a function to loop through a string, and "have a look at" every word in the

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