I have been working on a website for some time now, and the code I used here worked about a month ago, then I tried putting the file in a subfolder, and redirecting the move_uploaded_file function, but it doesn't seem to be working. To be specific, both the:
if((!empty($_FILES["uploaded_letter"])) && ($_FILES['uploaded_letter']['error'] == 0))
and
if((!empty($_FILES["uploaded_list"])) && ($_FILES['uploaded_list']['error'] == 0))
statements are returning false. If anyone could please help with that, that would be awesome! Thanks!
<html>
<head>
<title>VAA Chapter 11</title>
<!--favicon-->
<link rel="shortcut icon" href="favicon.ico" />
<!--global CSS-->
<link href="vaa.css" rel="stylesheet" type="text/css">
<!--local CSS-->
<style type="text/css">
</style>
</head>
<body>
<?php
function testPassword(){
$password = $_POST['password'];
if($password == 'You aint guessin this'){
echo 'welcome!!! <br/>
<form enctype="multipart/form-data" action="" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> <br/>
add newsletter: <input name="uploaded_letter" type="file" /><br/><br/>
add list: <input name="uploaded_list" type="file" /><br/><br/>
<input type="submit" name="load" value="Upload" />
</form>';
}
else{
echo "you have no power here";
}
}
function upload(){
if((!empty($_FILES["uploaded_letter"])) && ($_FILES['uploaded_letter']['error'] == 0)) {
$filename = basename($_FILES['uploaded_letter']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "pdf") && ($_FILES["uploaded_letter"]["size"] < 35000000)) {
$newname = dirname(__FILE__,1).'/newsletters/'.$filename;
move_uploaded_file($_FILES['uploaded_letter']['tmp_name'],$newname);
}
else {
echo "Error: file is too large";
}
}
else {
echo "Error: No file uploaded";
}
if((!empty($_FILES["uploaded_list"])) && ($_FILES['uploaded_list']['error'] == 0)) {
$filename = basename($_FILES['uploaded_list']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "txt") && ($_FILES["uploaded_file"]["size"] < 35000)) {
$newname = dirname(__FILE__,1).'/'.$filename;
move_uploaded_file($_FILES['uploaded_list']['tmp_name'],$newname);
}
else {
echo "Error: file is too large";
}
}
else {
echo "Error: No file uploaded";
}
}
function testUpload(){
if(isset($_POST['load'])){
upload();
}
}
?>
<form method="post">
<input type="text" name="password" />
<input type="submit" value="OK" />
</form>
<?php testPassword(); testUpload(); ?>
</body>
</html>