devofash Posted September 7, 2007 Share Posted September 7, 2007 Hello, I'm really stuck with the file upload. I submitted similar code a while ago in MSSQL section , but didnt get any reply at all so i've change the code but am still having problems. Some one please help. I'm running PHP 4.4, IIS 5.1 and mssql Ok, i'm uploading a PDF file to a directory, the upload works fine but when I download the file I get an eror "cannot open the file it may be corrupted". It really bugging me, I cannot figure out why its not working. the PDF files that I upload are fine but when I upload it I cant open them again. Please help. upload.php include_once('../includes/dbclass.php'); $uploadDir = "/upload/"; $fileName = $_FILES['userfile']['name']; $fileName = preg_replace("/[^a-z0-9-\.]/", "", strtolower($fileName)); $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $title = escapeQuotes($_POST['title']); $summary = escapeQuotes($_POST['summary']); $location = $_POST['location']; $ext = substr($fileName, strrpos($fileName, '.') + 1); if (($ext != "pdf") && ($fileType != "application/pdf")) { header('Location: error.php'); } else { $filePath = $uploadDir . $fileName; $result = move_uploaded_file($tmpName, $filePath); if (!$result) { header('Location: error.php'); exit; } require_once('../includes/dbclass.php'); $db = new dbase(); $db->db_connect(); $q = "INSERT INTO casestudies (title, summary, filename, filesize, filepath, whichpage) ". "VALUES ('$title', '$summary', '$fileName', '$fileSize', '$filePath', '$location')"; $results = $db->query($q); if($result) { header('Location: thankyou.php'); } else { header('Location: error.php'); } $db->db_close(); } download.php $q = "select * from casestudies WHERE id='$id'"; $results = $db->query($q); $numRows = $db->numRows($results); while($rows = mssql_fetch_object($results)) { $filename = $rows->filename; //$find = array("%20", "_", "-", "'"); //$replace = array(" ", "_", "-", "'"); //$filename = str_replace($find, $replace, $filename); $filesize = $rows->filesize; $filepath = $rows->filepath; header("Content-Disposition: attachment; filename=$filename"); header("Content-length: $filesize"); header("Content-type: application/pdf"); header("Cache-control: must-revalidate"); header("Content-Description: PHP Generated Data"); readfile($filepath); } and using this link to download relevent entries. echo "<a href='download.php?id=$rows->id'>"; I will really really appreciate if someone could help me out. Thank you in advance. Link to comment https://forums.phpfreaks.com/topic/68380-file-upload-problems-mssql-php-iis/ Share on other sites More sharing options...
eparrini Posted October 5, 2007 Share Posted October 5, 2007 I'm stuck with the same problem, and I am searching for a solution. Did you ever find a solution? Thank you, EP Link to comment https://forums.phpfreaks.com/topic/68380-file-upload-problems-mssql-php-iis/#findComment-362177 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.