您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

使用PHP上传文件并将路径添加到MySQL数据库

使用PHP上传文件并将路径添加到MySQL数据库

首先,您应该使用它print_r($_FILES)进行调试,然后查看其中包含的内容。:

uploads.PHP将看起来像:

//This is the directory where images will be saved
$target = "pics/";
$target = $target . basename( $_FILES['Filename']['name']);

//This gets all the other information from the form
$Filename=basename( $_FILES['Filename']['name']);
$Description=$_POST['Description'];


//Writes the Filename to the server
if(move_uploaded_file($_FILES['Filename']['tmp_name'], $target)) {
    //Tells you if its all ok
    echo "The file ". basename( $_FILES['Filename']['name']). " has been uploaded, and your information has been added to the directory";
    // Connects to your Database
    MysqL_connect("localhost", "root", "") or die(MysqL_error()) ;
    MysqL_select_db("altabotanikk") or die(MysqL_error()) ;

    //Writes the information to the database
    MysqL_query("INSERT INTO picture (Filename,Description)
    VALUES ('$Filename', '$Description')") ;
} else {
    //Gives and error if its not
    echo "Sorry, there was a problem uploading your file.";
}



?>

由于这是旧帖子,目前强烈建议在PHP中使用mysqlipdo代替MysqL_函数

php 2022/1/1 18:21:32 有378人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶