It appears you have not yet registered with our community. To register please click here.

Origin XT RPG Network Home







XT Project Introduction
Blah blah intro to this place. To be composed later.

uploading and downloading, cant declare it


Aug 4 2006, 09:42 AM (Post #1)
Peasant

Posts: 22
Cash: 9,001 / 0
Group: Newbie
Joined: 7/30/06 05:17 PM
ok, now i want to make a new ACT= page and in there to put a upload script to upload files into the server.
now i have managed to make the upload it is actually uploads to the directory i set.
but when i try to download it, it wont download.

here is how i did it:

i added a new table to the database:

CODE
CREATE TABLE ibf_vip (
 id int(5) NOT NULL auto_increment,
 mid int(5) NOT NULL,
 mname text NOT NULL,
 title text NOT NULL,
 va text NOT NULL,
 creator text NOT NULL,
 file text NOT NULL,
 approve char(1) NOT NULL DEFAULT 'N',
 PRIMARY KEY (id)
)


after that once u upload a file it inserst the data as follows:

CODE
            $DB->query("INSERT INTO ibf_vip (mid, title, va, creator, file, approve, mname) VALUES ('{$ibforums->member['id']}','$dtitle','$desc','$dcreat','$arealname1','Y', '{$ibforums->member['name']}')");


mid = the user number who uploaded
title = title that the user submitted
va = file description
creator = file creator
file = the file name
approve = is it approved? yes or no
mname = the user name who uploaded



now it is all ok for now, the file is uploaded into the directory i set, in inserts all the data to the DB correctly .
but when i try to download it it, says i dont have accsess to the path.

this is how i made the download:

in a new ACT= page i made a DB query to select all the data from the ibf_vip table.

after that i made a link to each row that is in the table.
and the link goes like this:

http://www.domain.com/index.php?act=page&CODE=03&id=1

the CODE i used to build the download function is like this:


CODE
  // the download function
function do_download( ) {
 GLOBAL $print , $DB , $ibforums , $std;
// the input id
 $id = $ibforums->input['id'];

// select the data

 $DB->query( "SELECT * FROM ibf_vip WHERE id = {$id}" );

 // Does the download exists?
 if( $DB->get_num_rows(  ) == 0 ) {
   $this->error("no_download");
 }

 // Are the members of this group allowed to download files?

        $vadim = "4|9|10|11|12|13";
           $group_ids=array();$group_ids = explode("|",$vadim);
              if (in_array($ibforums->member['mgroup'], $group_ids)) {
  $row             = $DB->fetch_row( );

// the actuall url for the download

               $download         = $ibforums->vars['upload_memurl'].$row['file'];

// insert data to the download logs

       $ip = $ibforums->input['IP_ADDRESS'];
       $time = time();
         $DB->query("INSERT INTO ibf_vdownload_logs (name, title, ip, date) VALUES ('{$ibforums->member['name']}','{$row['title']}','$ip', '$time')");

// print the header
    header("Location: ".$download);
    print "<a href='".$download."'>{$ibforums->lang['click_redirect']}</a>";
}
 else
 {
// no accsess
                 $this->error("no_enter");
               }
}
}




i am always getting a "page cannot be found"

although i tryed to download it from a direct link to the file and it worked.

if u thinking that the file isnt in the data base or the FTP ur wrong i double chacked and it is there.



help would be appriciated.
Post Options

2 Pages  1 2 > 
Aug 4 2006, 06:11 PM (Post #2)
Not Odd anymore
* * * * * * * * * *
Posts: 45,875
Cash: 1,915,578 / 1,817,041,051
Group: Administrator
Joined: 7/10/02 09:48 PM
First thing you need to do is to put an exit; statement right after header("location:") statement (which needs to be LOWERCASE).

Then you need to check the files: do a die($download); right before the header output to see if is redirecting you to the right place.

Anyway, I suggest you use readfile($download) instead (after pasting a bunch of headers telling the browser what type of file it is), because otherwise members will pass on the URL to the file again.
Post Options

Aug 5 2006, 06:52 PM (Post #3)
Peasant

Posts: 22
Cash: 9,001 / 0
Group: Newbie
Joined: 7/30/06 05:17 PM
tnx got it working.
Post Options

Aug 5 2006, 07:15 PM (Post #4)
Not Odd anymore
* * * * * * * * * *
Posts: 45,875
Cash: 1,915,578 / 1,817,041,051
Group: Administrator
Joined: 7/10/02 09:48 PM
What was your final code?
Post Options

Aug 6 2006, 01:36 PM (Post #5)
Peasant

Posts: 22
Cash: 9,001 / 0
Group: Newbie
Joined: 7/30/06 05:17 PM
CODE

function do_download( ) {
?GLOBAL $print , $DB , $ibforums , $std;
?$id = $ibforums->input['id'];

?$DB->query( "SELECT file,title FROM ibf_vip WHERE id = {$id}" );

?// Does the download exists?
?if( $DB->get_num_rows( ?) == 0 ) {
? ?$this->error("no_download");
?
}

?// Are the members of this group allowed to download files?

? ? ? ? $vadim = "4|9|10|11|12|13";
? ? ? ? ? ?$group_ids=array();$group_ids = explode("|",$vadim);
? ? ? ? ? ? ? if (in_array($ibforums->member['mgroup'], $group_ids)) {
? $row ? ? ? ? ? ? = $DB->fetch_row( );
? ? ? ? ? ? ? ?$download ? ? ? ? = $row['file'];
? ? ? ?$ip = $ibforums->input['IP_ADDRESS'];
? ? ? ?$time = time();
? ? ?$extra = "<font color=\"green\">- הורדת מוד -</font>";
? ? ? ? ?$DB->query("INSERT INTO ibf_vdownload_logs (name, title, ip, date) VALUES ('{$ibforums->member['name']}{$extra}','{$row['title']}','$ip', '$time')");
? ? header("location: ".$download);
exit();
}
?else
?{
? ? ? ?$ip = $ibforums->input['IP_ADDRESS'];
? ? ? ?$time = time();
? ? ? ? ?$DB->query("INSERT INTO ibf_venter_logs (mid, name, title, ip, date) VALUES ('{$ibforums->member['id']}','{$ibforums->member['name']}{$extra}','0','$ip', '$time')");
? ? ? ? ? ? ? ? ?$this->error("no_enter");
? ? ? ? ? ? ? ?}
}


This post has been edited by danny2: Aug 6 2006, 01:36 PM
Post Options

Aug 6 2006, 03:47 PM (Post #6)
Not Odd anymore
* * * * * * * * * *
Posts: 45,875
Cash: 1,915,578 / 1,817,041,051
Group: Administrator
Joined: 7/10/02 09:48 PM
Ah, you used exit(); after printing the header. Good job.

But members still know the URL of the files o_O Replace the header(); func with readfile($download); (leave everything else intact). Try it out
Post Options

Aug 7 2006, 01:49 PM (Post #7)
Peasant

Posts: 22
Cash: 9,001 / 0
Group: Newbie
Joined: 7/30/06 05:17 PM
u mean instead of this:

header("location: ".$download);

to use this:

readfile($download);

and it will do that same thing (make the download url) but without letting the members know what the url is?!
tnx
Post Options

Aug 7 2006, 05:43 PM (Post #8)
Not Odd anymore
* * * * * * * * * *
Posts: 45,875
Cash: 1,915,578 / 1,817,041,051
Group: Administrator
Joined: 7/10/02 09:48 PM
Yes, hopefully, depending what $download has.

do a die($download); and show me what kind of content $download has, and tell me where on your server the files are stored
Post Options

Aug 7 2006, 07:10 PM (Post #9)
Peasant

Posts: 22
Cash: 9,001 / 0
Group: Newbie
Joined: 7/30/06 05:17 PM
u mean do like so:

readfile($download);
die($download);

well once i upload a file into http://www.domain.com/forum/upload/filename.zip

it replaced by alink for example:

http://www.domain.com/forum/index.php?act=page&CODE=00&ID=1

the above link replaced fetches the data from DB about the file name in the FTP and created a download link.
Post Options

Aug 7 2006, 07:12 PM (Post #10)
Not Odd anymore
* * * * * * * * * *
Posts: 45,875
Cash: 1,915,578 / 1,817,041,051
Group: Administrator
Joined: 7/10/02 09:48 PM
no no, instead of readfile, do the die() statement so I know what's in $download. Then I'll tell you what to do instead
Post Options

Aug 7 2006, 07:14 PM (Post #11)
Peasant

Posts: 22
Cash: 9,001 / 0
Group: Newbie
Joined: 7/30/06 05:17 PM
i did what u said and it returned the direct download link to the file from the ftp.

like:
http://www.domain.com/forum/upload/filename.zip
Post Options

Aug 7 2006, 09:26 PM (Post #12)
Not Odd anymore
* * * * * * * * * *
Posts: 45,875
Cash: 1,915,578 / 1,817,041,051
Group: Administrator
Joined: 7/10/02 09:48 PM
It's supposed to. Give me the exact data, please. I want to find out of readfile() would work in this situation.
Post Options

Aug 8 2006, 01:34 PM (Post #13)
Peasant

Posts: 22
Cash: 9,001 / 0
Group: Newbie
Joined: 7/30/06 05:17 PM
this what it outputs http://www.domain.com/forum/upload/filename.zip
just instead of domain.com there is my domain name.
and i tryed the readfile thing and once i pressed a donwload link it outputs alot of crap in the page.
Post Options

Aug 8 2006, 05:27 PM (Post #14)
Not Odd anymore
* * * * * * * * * *
Posts: 45,875
Cash: 1,915,578 / 1,817,041,051
Group: Administrator
Joined: 7/10/02 09:48 PM
Try this then, instead of the readfile():

CODE

$url = parse_url($download);
$file = $_SERVER['DOCUMENT_ROOT'].$url['path'];

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"" . basename( $file). "\"");
header("Content-length: " . (string)(filesize($file)));
header("Expires: " . gmdate("D, d M Y H:i:s", mktime(date("H") + 2, date("i"), date("s"), date("m"), date("d"), date("Y"))) . " GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

readfile($file);


If that doesn't work, try this:

CODE

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"" . basename( $download). "\"");
header("Expires: " . gmdate("D, d M Y H:i:s", mktime(date("H") + 2, date("i"), date("s"), date("m"), date("d"), date("Y"))) . " GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

readfile($download);
Post Options

Aug 8 2006, 06:02 PM (Post #15)
Peasant

Posts: 22
Cash: 9,001 / 0
Group: Newbie
Joined: 7/30/06 05:17 PM
the first one worked tnx, now how can i be sure that no one can actually see the direct link?
tnx again.
Post Options

2 Pages  1 2 >