7 Replies - 1034 Views - Last Post: 10 July 2008 - 07:22 AM Rate Topic: -----

#1 ndrew  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 25
  • View blog
  • Posts: 312
  • Joined: 21-April 08

Download from MySQL and PHP

Posted 08 July 2008 - 08:10 PM

Ok I have alot of problems with my site AndyScripter and for some reason i can find why my downloads wont work...
So heres the upload form
<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$title   = $_POST['title'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}

include 'config.php';
include 'opendb.php';

$query = "INSERT INTO free_upload (name, size, type, content, title ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$title')";

mysql_query($query) or die('Error, query failed');
include 'closedb.php';

echo "<br>File $fileName ($title) uploaded<br>";
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://www.qescripter.uni.cc/style.css" >
</head>
<body>
<center>
<img src="/images/uploads.png" >
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="100">Title</td>
<td><input name="title" type="text"></td>
</tr>
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
</center>
</body>
</html>


and heres the download form
<?php
include 'http://andyscripter.uni.cc/header.php';
include 'http://andyscripter.uni.cc/body.php';
?>
<?php
if(isset($_GET['id']))
{
// if id is set then get the file with the id from database

include 'config.php';
include 'opendb.php';

$id    = $_GET['id'];
$query = "SELECT name, type, size, content " .
         "FROM free_upload WHERE id = '$id'";

$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content, $title) = mysql_fetch_array($result);

header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;

include 'closedb.php';
exit;
}

?>
<?php
include 'config.php';
include 'opendb.php';

$query = "SELECT id, name, title FROM free_upload";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $name, $title) = mysql_fetch_array($result))
{
?>
<li><a href="index.php?id=<?php echo $id;?>"><?php echo $title;?></a> <br>
<?php
}
}
include 'closedb.php';
?>
<?php
include 'http://andyscripter.uni.cc/footer.php';
?>

And when i click the file i want to download well this happens..
WARNING MOMBO JUMBO!
�@�`6B� @�q@��UH��VW}W��EEtWDq@�@>B���S]]t+��E!��xB�WV}��t h @�V��W ��?�u =xB�\uh@�Wi��W]��؍PV@q@�E���j?P3��8�t }�tu>.uFth<.u~�t^VS��tE<uDuW9W~��WDq@�u EtWjKj�W��>B�Wj1PuB�@WD��t6W6���W��Wp@�uEtWjVWk��Wj_^�Vt$V��PVq@�8\th@�V��^�D$ :L$t Pr@�u�Vt$V��ƀ8\tPVq@�;w �@^�L$  f9\\tB�t t<\t+��t�tVV��;VVxp@�3Ƀ_^�SVWt$��t$"t$7$7�Vp@�7tVr@�V��;}3_^[�L$Vt$~D$+ANu^�t$xp@�t $Pt$p@��t$xp@�j�A#Qt$j�jt$t$p@��UVuWjd_OEnsa�p@�j3YVEj�Pu�U p@�u uЀ&�_^]�SUVWj��t$tjVt$Ѕ9��hp@��&B�NUL�����&B�t&jj�V=Pp@�WUVӅ��;���x B�WVt$Ӆ���;���VUh,@�hxB��r@�ءp>B�(��V'��jh���Vl$���j�Up@�D Pj@�q@�toD$j�PWVU,q@�t[;|$uUhs@�VuZ>hs@�P�� ShxB�P3PPPU4q@�D$j�PWVU(q@�Vp@�Up@�>B�_^][� h(@�Pt@>;sU�+E;rl$+USEVPE3u%��� ��PSuup@�u>EE���PEVPSuu�p@�u}t}tu��p@�^[]�t$hs@�t$�r@��UQMSVW39-E��� 9uAM90uA0| 77߀XuAA0|;0<u!߃A|F ƋE_^[�h���t$t$p@��%p@�%p@�UE} <6B����+ȋ >B�Uȸ�.B�S+VW�����}e���+�����AM��A EEـ̀̀]ME��j^p@�yf=Zt}#t}.te�E���=>B��tj^y7Ã?>B�@PWShs@�h��?����uW���%uh���Wp@�q$uhh���Wp@�3Xd>B�3N;t9MtWQQt5h>B�Ѕt8EPt5h>B�dq@�uWuPq@�uxr@�u'�u?�t}uhHs@�WLW���Du.u5h>B�Wp �@B�PWsŀu+PWWM�.B� uGAG*'�}�_^[t Pu�SVt$W>\u~\u~?u ~\u>�tVtFFބt9U-r@�<v"Ph4@�n8�uV+PVWWՋVՋu]'�WSq@�< t<\u'�;r_^[�V$B�Vt$@q@�tP8q@�3^�D$VW@�Wq@�uWp@�t @�Pq@�_^�UVuW=q@� EPq@�jVVEj�Pׅu_^�=*B��Vu-3j^Ѐҁ 3Nu�*B�A���|ՋT$D$v#L$W9���34�*B�3AJu_^����H�uIx3@AhAdA`A\U���SVWj"Yxp}u3@ ��]ux ��$$g@�}� ��EME�< ��j-Yj Y™3҉}BJU3B7���JU6��<6;}t&}�t up@�Wj@�q@�Ey ��}tENfp�ue�e�&}���EMȋE� EEE}|ԋE;Et(}�Et up@�uj@�q@�E� ��EME���d�!}�E��MEM EEEMuՋE M#EDž|���EȋE4Hl��39UuoEu *M#uMMƍ@ }l��E}U} }mm9UtE+E;ErEM3CEh3C��EME���Dž|���H����}�g��MEe MEEE9E��������EeME@Í4AMfu9Mse�M���+f)M)MfE���f+\f}���]qG}���MEe MEE���}\EM4fu9MsM���+f)M)MfȍZf+f}���]swe�EE}�?��MEUE EMMA3u��}���MEe MEE���}EM4fu9MsM���+f)M)MfȍZf+f}���]sw}uEMDž|���H��

All this weird mombo jumbo stuff! So im wondering what did I do wrong?
Site: http://andyscripter....downloads/free/

ndrew
Attached File  index.php (1.11K)
Number of downloads: 23
Attached File  uploadfree.php (1.47K)
Number of downloads: 25

Is This A Good Question/Topic? 0
  • +

Replies To: Download from MySQL and PHP

#2 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Download from MySQL and PHP

Posted 08 July 2008 - 10:20 PM

header("Content-length: ".$size);  
header("Content-type: ".$type);  
header("Content-Disposition: attachment; filename=".$name); 


i'm not 100% positive (since i rarely, if ever, work with Files), but it should work =P

i think you just used the variables as a string instead of as an actual variable... remember if you echo "$hello"? it displays $hello, not the text in it...
Was This Post Helpful? 1
  • +
  • -

#3 ndrew  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 25
  • View blog
  • Posts: 312
  • Joined: 21-April 08

Re: Download from MySQL and PHP

Posted 09 July 2008 - 01:34 AM

Ok I have more news on the problem...... its my title... if i get rid of that from the rest it works perfectly!

This post has been edited by ndrew: 09 July 2008 - 01:37 AM

Was This Post Helpful? 0
  • +
  • -

#4 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Download from MySQL and PHP

Posted 09 July 2008 - 09:01 AM

makes sense... you shouldn't need a title on the download section anyway, because it opens the browsers popup box =)
Was This Post Helpful? 0
  • +
  • -

#5 ndrew  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 25
  • View blog
  • Posts: 312
  • Joined: 21-April 08

Re: Download from MySQL and PHP

Posted 09 July 2008 - 10:19 PM

View PostJBrace1990, on 9 Jul, 2008 - 09:01 AM, said:

makes sense... you shouldn't need a title on the download section anyway, because it opens the browsers popup box =)


Well i want a title so people know what exacly there downloading...
eg: Well looky here im going to download cssinfoveiw.exe mmmm sounds like a virus Ill be off then.

Well looky here im going to download Counterstrike:Source Xfire Info Veiw. Well im gonna give that a go :D

And if I get title to work then comments then a whole new way to download stuff!!!!

ndrew
Was This Post Helpful? 0
  • +
  • -

#6 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1147
  • View blog
  • Posts: 7,133
  • Joined: 07-September 06

Re: Download from MySQL and PHP

Posted 10 July 2008 - 12:19 AM

Quote

And if I get title to work then comments then a whole new way to download stuff!!!!

If you do succeed make sure to post it here, and how to accompluish it :)

Though, I think the easiest way to accomplish what you are talking about is to create a stand along app that the user can download that uses a socket connection (on the download page via Flash) to see when a file should be downloaded (and what file it is) and then popup a custom made window to confirm that the download is allowed and where the user wants to save it to. But that is just me, and may be totally off the wall...
Was This Post Helpful? 0
  • +
  • -

#7 ndrew  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 25
  • View blog
  • Posts: 312
  • Joined: 21-April 08

Re: Download from MySQL and PHP

Posted 10 July 2008 - 02:26 AM

View PostBetaWar, on 10 Jul, 2008 - 12:19 AM, said:

Quote

And if I get title to work then comments then a whole new way to download stuff!!!!

If you do succeed make sure to post it here, and how to accompluish it :)

Though, I think the easiest way to accomplish what you are talking about is to create a stand along app that the user can download that uses a socket connection (on the download page via Flash) to see when a file should be downloaded (and what file it is) and then popup a custom made window to confirm that the download is allowed and where the user wants to save it to. But that is just me, and may be totally off the wall...


Well I did figure it out :D ITS IMPOSSIBLE! With out a 2 parts.
1st part is the File.
2nd part is the Title and comment.

Havent finished the code but will post ASAP till i get it all worked out.

Thank-you.

P.S. Your idea of flash makes me think about making it... means I have to install Flash MX 2004 again :(
Was This Post Helpful? 0
  • +
  • -

#8 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1147
  • View blog
  • Posts: 7,133
  • Joined: 07-September 06

Re: Download from MySQL and PHP

Posted 10 July 2008 - 07:22 AM

No problem, I have been thinking about making an advanced download system for some time and Flash is the easiest way I have found at making the proper connections to the client's computer. I have looked around at a lot of other possibilities (even into what framework microsoft usesto call programs to run, etc. from the web) Flash still looks the easiest...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1