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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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