UPloading files

若如初见. 提交于 2019-12-25 05:13:38

问题


I have a question about how the upload and download system works with php and mysql.

I want to upload mp3 files so that only a specific user(logged in) can view available files sorted in some catagories and download the ones he/she wants while few of them would be available publicly and anyone can download them

I feel really stupid asking this but where is the files then saved? Inside a table? Or does the table point to a directory in my webserver? and how to store the file path into the database. udload should take place on server side not on the webpage. My audio files are available on local disk.

I'm asking this as I really want to learn this but even the basic questions can be difficult even to formulate let alone solve... :)

I am stuck as i want to store the file path in database so it can be downloaded by users.

Looking forward for some input


回答1:


$target = "/path_to_folder/";// target to which the file needs to be saved

$filepath = $target . basename( $_FILES['filename']['name']);// path of the file in server

//upload file like this
if(move_uploaded_file($_FILES['filename']['tmp_name'], $target))
{

// here insert $filepath in to DB

$con = mysqli_connect("localhost","username","password","dbanme");

$query = "insert in tablename(filepath) values($filepath)";

$result = mysqli_query($con,$query) or die (mysqli_error($con));

}


来源:https://stackoverflow.com/questions/22326248/uploading-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!