Jump to content

Downloads Script not working


epiC)Jimmy

Recommended Posts

Hello,

I am very new to php. I really don't know what I'm doing half the time. For some reason this download script is not working. After I upload a file I notice that the public_html/downloads folder does not have the file in it, although the script said success to the upload. Idk is this thing uploading to the folder at all? Or is it uploading to the MySQL server? Also, after the upload, when I got to the downloads.php page and click on the DOWNLOAD NOW! link it just acts as if there was a backslash in the link address because it returns me to the websites homepage. Can someone please take a look at the script and tell me if anything is wrong?

 

public_html/include/console/adddownload.php

=====================================================

<?php

 

if(checkLogin(MEMBER_NAME, MEMBER_PASS) AND checkRank(MEMBER_RANK, $pid)) {

 

 

if($submit) {

echo "<table align='center' border='0' cellspacing='0' cellpadding='0' width='450'>";

 

if($fileurl == "" AND $downloadfile != "" AND is_numeric($type1) AND $name1 != "") {

$dlfilepath = basename($_FILES['downloadfile']['name']);

 

 

$dlextensions = getDownloadCatInfo("extension", $type1);

$totalextensions = substr_count($dlextensions, ",");

 

$passtest = 0;

if($totalextensions > 0) {

$dl_extensions = str_replace(" ", "", $dlextensions);

$dl_extensions = explode(",", $dl_extensions);

 

foreach($dl_extensions as $ext) {

$countext = strlen($ext);

$startpos = 0-$countext;

$testfile = substr($dlfilepath, $startpos);

 

if($testfile == $ext) { $passtest++; }

 

}

}

else {

$countext = strlen($dlextensions);

$startpos = 0-$countext;

$testfile = substr($dlfilepath, $startpos);

 

if($textfile == $ext) { $passtest++; }

}

 

if($passtest == 0) {

$diemessage = "The download could not be added.  The file must be of type: $dlextensions";

die("<script language=\"Javascript\"> alert(\"$diemessage\"); window.location.href = 'console.php?pid=$pid'; </script>");

}

 

$failed = 0;

if(@move_uploaded_file($_FILES['downloadfile']['tmp_name'], "downloads/".$dlfilepath)) {

echo "<tr><td class='main'>File Uploaded Successfully!</td></tr>";

$failed = 0;

}

else {

echo "<tr><td class='main'>File Upload Failed!</td></tr>";

$failed = 1;

}

 

if($failed == 1) {

echo "<tr><td class='main'>File Upload Failed: The file was unable to be uploaded!</td></tr>";

}

else {

$filenamepath = "downloads/$dlfilepath";

$outsidelink = 0;

}

}

elseif($fileurl != "") {

$filenamepath = $fileurl;

$outsidelink = 1;

$failed = 0;

}

 

if(!is_numeric($type1) OR $name1 == "") { $failed = 1; }

 

if($failed == 0) {

foreach($_POST AS $key => $value) { ${$key} = addslashes(textFilter($value)); }

$time = time();

$query = "INSERT INTO {$dbprefix}downloads (name, description, type, poster, filename, outsidelink, adderip, dateadded) VALUES ('$name1', '$desc', '$type1', '$memid', '$filenamepath', '$outsidelink', '$ip', '$time')";

$result = mysql_query($query)

    or die(mysql_error());

 

echo "

</table>

<script language=\"Javascript\">

alert(\"Success!\");

window.location.href = 'console.php';

</script>

";

}

else {

echo "

<tr><td class='main'>The download was not added to the database.</td></tr>

</table>

";

}

 

 

 

}

elseif(!$submit) {

$maxuploadsize = ini_get('upload_max_filesize')."B";

$downloadcats = getDownloads();

foreach($downloadcats as $download) {

$options .= "<option value='$download[1]'>$download[0]</option>";

}

$dispconsolename = getConsoleInfoByID("displayname", $pid);

echo "

<form action='console.php?pid=$pid' method='post' enctype='multipart/form-data'>

<table align='center' border='1' cellspacing='0' cellpadding='3' width='500' bordercolor='$bgcolor'>

<tr>

<td bordercolor='$bordercolor' background='themes/$theme/$bgimage' class='titles' align='center'><b>$dispconsolename</b></td>

</tr>

<tr>

<td bordercolor='$bordercolor' style='border-top-width: 0px' class='main'><br>

<blockquote>

<b>NOTE:</b> If both the Upload File and File URL are used, the File URL will be added to the database.  It will overwrite any file with the same name.<br><b>MAX UPLOAD SIZE: $maxuploadsize</b><br><br>

<center>

<table align='center' border='0' cellspacing='0' cellpadding='0' width='450'>

<tr>

<td class='main' width='150'><b>Upload File:</b></td>

<td class='main' width='300'><input type='file' name='downloadfile' class='form'></td>

</tr>

<tr><td align='center' class='main'><br><i>OR</i><br><br></td></tr>

<tr>

<td class='main' width='150'><b>File URL:</b></td>

<td class='main' width='300'><input type='text' name='fileurl' class='form'></td>

</tr>

<tr>

<td class='main' width='150'><b>Name:</b></td>

<td class='main' width='300'><input type='text' name='name1' class='form'></td>

</tr>

<tr>

<td class='main' width='150'><b>Type:</b></td>

<td class='main' width='300'><select name='type1' class='form'>$options</select></td>

</tr>

<tr>

<td class='main' width='150' valign='top'><b>Description:</b></td>

<td class='main' width='300'><textarea name='desc' rows='4' cols='40' class='form'></textarea></td>

</tr>

 

<tr>

<td colspan='2' class='main' align='center'><br><input type='submit' name='submit' value='Add Download'></td>

</tr>

 

</table>

</center>

</blockquote>

</td>

</tr>

</table>

</form>

";

}

 

}

else {

echo "

<table align='center' border='0' cellspacing='0' cellpadding='0' width='400'>

<tr>

<td class='main' align='center'>Your rank is not high enough to view this page</td>

</tr>

</table>

";

}

 

?>

 

=====================================================

 

 

 

 

public_html/include/downloads.php

=====================================================

<br>

<center><h2>Downloads</h2></center>

 

<?php

 

$dlcat = textFilter(getDownloadCatInfo("name", $dl));

 

echo "

<table align='center' border='0' cellspacing='0' cellpadding='2' width='500' bordercolor='$bgcolor'>

<tr>

<td class='titles' style=\"border: solid $bordercolor 1px\" background='themes/$theme/$bgimage' bordercolor='$bordercolor' align='center'><b>$dlcat</b></td>

</tr>

<tr>

<td class='main' style=\"border: solid $bordercolor 1px; border-top-width: 0px\">

<br>

<blockquote>

";

$query = "SELECT * FROM {$dbprefix}downloads WHERE type = '$dl' ORDER BY name";

$result = mysql_query($query)

    or die(mysql_error());

while($row = mysql_fetch_array($result))

{

extract($row);

foreach($row AS $key => $value) { ${$key} = textFilter($value); }

 

$dispName = addslashes(textFilter(getMemberInfoByID("username", $poster)));

$dispRank = addslashes(textFilter(getRankInfo("name", getMemberInfoByID("rank", $poster))));

$dispDate = date("m/d/y", $dateadded);

echo "

<b>File Name:</b> $name<br>

<b>Posted By:</b> <a href='index.php?p=Profile&user=$dispName'>$dispRank $dispName</a><br>

<b>Date Posted:</b> $dispDate<br>

<b>Description:</b><br>

$description<br><br>

<b><a href=\"$filename\">DOWNLOAD NOW!</a></b>

<hr size='1' width='500' color='$bordercolor'><br>

";

}

 

echo "

</blockquote>

</td>

</tr>

</table>

";

 

?>

=====================================================

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.