tags:

views:

19

answers:

1

I would like to upload different types of files pressumably pdfs to a certain directory I am currently trying to get this one script working that I found on snipplr but it is not working as I assumed it would, here is my code.

Never mind I had an extra comma in my code

UPDATE: I added some more code in comments below, I want to also add the filename to a field in a datatbase, currently the script I have breaks the page nothing loads I am not sure why since it seems to work on other pages I have.

<?php
if( isset($_POST['submit']) )
    {

    $target_path = "../downloads/";
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ".  basename( $_FILES['uploadedfile']['name'])." has been uploaded";

/*
        $title = basename( $_FILES['uploadedfile']['name']);
        $sql = sprintf("INSERT INTO forms (title)VALUES('%s')",
        mysql_real_escape_string($title)
        );
        $results = mysql_query($sql)or die(mysql_error());
*/
    } else{
        echo "There was an error uploading the file, please try again!";
    }

}
?>

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
        <input type="file">
        <input type="submit" name="submit" value="submit"  />
</form>
A: 

Apart from the directory existing, file permissions, etc., you might want to give your input a name:

<input type="file" name="uploadedfile">
jeroen
Cool thats what i was missing. As far as permissions go I am using a script to lockdown the page where a username and password are required to enter.
Anders Kitson
I was wondering if you could help me out again, I added some new code that I am just now having a issue with, thanks again.
Anders Kitson
You seem to have a comma too much after `$sql = sprintf("INSERT INTO forms (title)VALUES('%s')", mysql_real_escape_string($title)` but if that´s not it, you´d better as a new question using the right tags.
jeroen
that was it, the extra comma.
Anders Kitson