Hey All-- I need a suggestion regarding PHP File Upload System-- I have a user table having user's information, and an upload table having upload information, how i distinguish that these files belong to the specified user? I am in trouble from a bit days-- Example: User Table > Jhon Jhon upload these file > document.pdf > cv.doc > exam.ppt how should i display these from table? Please Help
You need two table: Users table and Uploads table. You already have your Users table, I am guessing there is an Auto Increment field, for some sort of user_id? Now, create your upload table: upload_id int(8) Auto Increment user_id int(8) upload_filename varchar(255) You can add other fields like filesize, file type, etc. For each upload, you will be entering a new row in that table, making sure user_id is the ID of the user doing the uploading. To fetch all uploads from a single user, just do a simple query: 'SELECT * FROM uploads WHERE user_id = ' . (int) $user_id;
if(!isset($_POST['upload'])) { } else { $yourdomain = 'http://www.yourdomain.com/'; //$uploaddir = 'upload/'; $filename = $_FILES['file']['name']; $filetype=$_FILES['file']['type']; $filesize = $_FILES['file']['size']; $tmpname_file = $_FILES['file']['tmp_name']; $date_file = date(dmy); if(($filetype=="jpeg")|| ($filetype=="gif")|| ($filetype=="png") && ($filesize<20000) ) { if(file_exists($filename)) { echo "file is already exist"; } else { move_uploaded_file($tmpname_file, "$filename"); } } else { echo "invalid file"; }