Jump to content

Files downloaded from database corrupt/not keeping file extension


mikeg542

Recommended Posts

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;
}

  • 3 weeks later...

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.