rhodesa Posted January 21, 2009 Share Posted January 21, 2009 after you upload a file, do you see the file show up with the proper linknum in the uploads dir? and does it have data in it? (basically confirming upload.php is working properly) are the download.php and upload.php scripts in the same directory? try this for download.php: if(isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); $query = "SELECT linknum, typefile, sizefile, namefile FROM items WHERE linknum = '$id'"; $result = mysql_query($query) or die('Error, query failed' . mysql_error()); if(!mysql_num_rows($result)) die("File not found"); list($file, $type, $size, $name) = mysql_fetch_array($result); header("Content-type: $type"); header("Content-length: $size"); header("Content-Disposition: attachment; filename=$name"); header("Content-Description: PHP Generated Data"); readfile('uploads/'.$file); exit; } Link to comment https://forums.phpfreaks.com/topic/141606-files-downloaded-from-database-corruptnot-keeping-file-extension/page/2/#findComment-742625 Share on other sites More sharing options...
mikeg542 Posted February 9, 2009 Author Share Posted February 9, 2009 The file is being uploaded with 0 bytes The code I have is: if (isset($_POST['upload'])) { $linkchars = 'BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz123456789'; $link = ''; for ($x=0; $x < 8; $x++) { $link .= $linkchars{rand(0, strlen($linkchars)-1)}; } $fileName = mysql_real_escape_string($_FILES['userfile']['name']); $fileSize = mysql_real_escape_string($_FILES['userfile']['size']); $fileType = mysql_real_escape_string($_FILES['userfile']['type']); $query = "INSERT INTO items (namefile, sizefile, typefile, content, linknum, sentstaffid, recievedstaffid, clientname) ". "VALUES ('$fileName', '$fileSize', '$fileType', '', '$link', '', '', '')"; $tmpName = $_FILES['userfile']['tmp_name']; move_uploaded_file($tmpName,'uploads/'.$link); mysql_query($query) or die('Error, query failed:'. mysql_error()); echo "<br>File $fileName uploaded<br>"; ?> <form method="post" name="userform"> <input type = "hidden" name ="linknum" value ="<?=$link?>" /> <select name="userchoice"> <option value="default"></option> <option value="staff"> Staff </option> <option value="client"> Client </option> </select> <input type="submit" name="usersubmit" value="Ok!"/> </form> <?php } This is on a page with a large amout of other code, if this would effect it... Link to comment https://forums.phpfreaks.com/topic/141606-files-downloaded-from-database-corruptnot-keeping-file-extension/page/2/#findComment-758370 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.