The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.34 / 5.00 31,296 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.07 / 5.00 10,082 ViewsThe code you provided works in a very limited sense, being that it never calls the checkExt($f) function and uploads any file without regard like a blind, deaf, and retarded border patrol guard.
The only thing wrong is on this line:
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
You upload a file named "uploaded" but then try to reference a file named "uploadedfile". Thus the message you send back to the user is always "The file has been uploaded". Pick one or the other.
Also $ok=1 is sitting at the front of your code and never used. Get rid of it.
Alright now your checkExt() function. This was baffling to me. You created an array of good file extensions and then tried to determine if your file's extension was included in that array. That's fine. But using regex, especially ereg (deprecated) is putting yourself through hell and back. Regex takes a long time to perfect, and there is always some case that will slip through the cracks. If you are looking for a file extension, why not just base it off of strings?
$extension = substr($filename, strrpos($filename, '.'));
As for the file size, let me not be a dick by pointing you to lmgtfy. You can instead feel dumb by looking here.
$validSize = filesize($_FILES['uploaded']['tmp_name'])<=15728640;//15 MB
So, here is my final version of your code.
<?php
$folder = "uploads/";
$name = $_FILES['uploaded']['name'];
$tmpname = $_FILES['uploaded']['tmp_name'];
function validFile($name,$tmpname)
{
$name = strtolower($name);
$allowed = array('.swf','.exe');
$extension = substr($name,strrpos($name,'.'));
$validSize = filesize($tmpname)<=15728640;//15 MB
return in_array($extension,$allowed)&&$validSize;
}
if(validFile($name,$tmpname)&&move_uploaded_file($tmpname, $folder.$name))
echo "The file $name has been uploaded";
else
echo "Sorry, there was a problem uploading your file.";
?>
~fourthfrench
Your problem is scope.
You have two places in your code with JavaScript: the upper code block and the lower Onclicks.
You meant to define one global variable named goose that could be read by both.
You actually defined two local variables in each (var goose = false, var goose = true).
Therefore if(goose == true) will always evaluate to false, since you never change goose's value to true.
In summation, var goose = false and var goose = true are two completely different variables. You could name them var fourth = false and var french = true and see no difference.
To fix your code, you need to make those two variables one variable. Or, more accurately, make a global variable instead of 2 local ones. There are several ways you can do this, but the easiest way to show you is by just appending the value of goose to window.
Change your code to this:
<script type="text/javascript">
window.goose = false;
function changegoose() {
if (window.goose==true) {
var gooseimage = document.getElementById("thegoose");
gooseimage.src = "http://www.birding.in/images/Birds/bean_goose.jpg"
}
}
</script>
<a href="#" OnClick="window.goose=true">make true</a>
<a href="#" OnClick="changegoose();">Click</a>
</p>
<p><img id="thegoose" src="http://umphulump55.files.wordpress.com/2009/07/goose.jpg" alt="Goose" /></p>
~fourthfrench