After taking a break for 5 minutes I came back and realized where I went wrong. Correct code below;
echo'<a href="download.php?code='.$unique_code.'">Click</a>';Thanks anyway for your help, ScTech
echo'<a href="download.php?code='.$unique_code.'">Click</a>';Thanks anyway for your help, ScTech
<?php include("core/init.inc.php"); if(isset($_FILES['file'])){ $file_name = mysql_real_escape_string($_FILES['file']['name']); // To create the code we will create a charset from an array of letters and numbers and jumble it. $charset = array_flip(array_merge(range('a','z'), range('A','Z'), range(0, 9))); // The unique code is then created from taking 12 letters and numbers from the charset we just made and turn them into one string.. You can change this number to anything, but remember to change the length in the table as well. $unique_code = implode('', array_rand($charset,12)); // Insert the filename and unique code into the files table. mysql_query("INSERT INTO `files` (`file_code`, `file_name`) VALUES('{$unique_code}', '{$file_name}') "); move_uploaded_file($_FILES['file']['tmp_name'], "core/files/{$_FILES['file']['name']}"); echo'<a href="download.php?code='.$unique_code.'">Download File</a>'; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="" type="text/css"/> <title>Temporary Url</title> </head> <body> <form action="" method="POST" enctype="multipart/form-data"> <p><input type="file" name="file" /></p> <p><input type="submit" value="Upload"/></p> </form> </body> </html>
if(isset($_FILES['file'])){to
if(isset($_FILES['file']) && !empty($_FILES['file'])){it should stop the upload happening if there's no file.