开发者

uploading different types of files mostly pdfs

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['uploadedfi开发者_高级运维le']['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>


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

<input type="file" name="uploadedfile">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜