0

I'm trying to create a form that allows me to upload only html files to a web directory via php and then delete them after 24 hours of being on my server. Whenever I go to upload a file I just get a blank white page. Can somebody help me figure this out please? Many thanks!

<?php 
if (($_FILES["uploaded"]["type"] == "html")
{
    $target = "users/"; 
    $target = $target . basename( $_FILES['uploaded']['name']) ; 
    $ok=1; 

    echo "File: " . $_FILES["uploaded"]["name"] . "<br />";
    echo "Type: " . $_FILES["uploaded"]["type"] . "<br />";
    echo "Size: " . ($_FILES["uploaded"]["size"] / 1024) . " Kb<br />";
    echo "Location: users/" . $_FILES["uploaded"]["name"];

    $files=shell_exec('find /users/ -mmin +1440');
    $file = explode("\n",$files);
    if(isset($file) && is_array($file))
    {
        foreach($file as $val)
        {
            @unlink($val);
        }
    }
}

else 
{
    echo "Sorry, " . $_FILES["uploaded"]["name"] . " is not a valid html document. Please try again.";
    unlink . $_FILES["uploaded"]["name"];
}
?> 
user3742063
  • 11
  • 1
  • 6

1 Answers1

0

There is a missing parentheses closing first IF. Then at that last line unlink . $_FILES["uploaded"]["name"]; you probably mean unlink() Blank page makes me think you have error reporting off. Turn it on when you code :)

<?php 
if(($_FILES["uploaded"]["type"] == "html")){
    $target = "users/"; 
    $target = $target . basename( $_FILES['uploaded']['name']) ; 
    $ok=1; 

    echo "File: " . $_FILES["uploaded"]["name"] . "<br />";
    echo "Type: " . $_FILES["uploaded"]["type"] . "<br />";
    echo "Size: " . ($_FILES["uploaded"]["size"] / 1024) . " Kb<br />";
    echo "Location: users/" . $_FILES["uploaded"]["name"];

    $files=shell_exec('find /users/ -mmin +1440');
    $file = explode("\n",$files);
    if(isset($file) && is_array($file))
    {
        foreach($file as $val)
        {
            @unlink($val);
        }
    }
}

else {
    echo "Sorry, " . $_FILES["uploaded"]["name"] . " is not a valid html document. Please try again.";
    unlink($_FILES["uploaded"]["name"]);
}
?> 
nocarrier
  • 129
  • 6
  • Oops! Thanks for catching that. However for some reason it's giving me an error now when I try uploading a .html file. Is "html" the proper reference in PHP for html? – user3742063 Aug 24 '14 at 23:03
  • You could try var_dump($_FILES) or var_dump($_FILES['uploaded']) to see what it contains. Also you have a related thread [link](http://stackoverflow.com/questions/15605030/php-filesfiletype-is-useless) – nocarrier Aug 24 '14 at 23:28
  • I figured out the error. I had to add text to html for accepted file types. My only problem now however though is that files are not being put into "users/" – user3742063 Aug 25 '14 at 01:19