PHP Creating Secure File Upload - Help

Hello, i have a problem in developing a secure file upload/download system using php, whereby in this code, there is no restriction in choosing any file type, but there is restriction on file size. and the file info will be stored in the database.


i’m stucked in creating a upload form whereby there is an message box popped out saying “there is an error due to no file selected” when i click on the upload button without selecting any file

need help in setting the file size below 3MB whereby if i upload file more than 3MB there will be a message box popped out saying “maximum file size!” instead of showing Undefined index: on top of the browser

Here are the code in uploadaction.php
include “db_connect.php”;
$uploaddir = ‘folder/’;
$uploadfile = $uploaddir . basename($_FILES[‘myfile’][‘name’]);
move_uploaded_file($_FILES[‘myfile’][‘tmp_name’], $uploadfile);
$id = ‘id’;
$filename = $_FILES[‘myfile’][‘name’];
$title = $_POST[‘title’];
$name= $_POST[‘name’];
$date= date(“Y-m-d”);
$time= date(“H:i:s”);
// we got the name, so we just proceed to store them

$q = mysql_query(“INSERT INTO files values (’$id’,’$filename’,’$title’,’$name’,’$date’,’$time’)”);

require “download.php”;


here are the form in download.php

Title :

File :

  • the form is on download.php whereby it will refer to uploadaction.php to do the upload
    i’ve tried to find code from other sources but it didnt help, would love if javascript coding can be added to improve this coding. Thank you so much~
Sponsor our Newsletter | Privacy Policy | Terms of Service