Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › Ajax/php respone problem
New Posts  All Forums:Forum Nav:

Ajax/php respone problem - Page 2

post #11 of 18
Could you explain a bit more? I'm not sure I see the connection between getdownloadsubname.php and $_FILES. You mean after the form is submitted, there's nothing in the $_FILES superglobal?

Also, you should be using mysqli_ for all your database queries, replaces the antiquated mysql_
post #12 of 18
Thread Starter 
I have figured out that I can upload certain files. I can not upload files such as .rar which is all I need to upload. The .rar upload leaves $_files array empty on the query page while files like .html .xml work fine. Any suggestions? Also what is mysqli? I have never heard of it before.
post #13 of 18
That's odd, do you have any restrictions in place as far as extensions and such? Is any of the data being upload being processed in any way?

It's the newer PHP command for interacting with MySQL databases (mysqlimproved). It's faster and can take advantage of some of the newer MySQL functions. Queries are the same, all you have to do is add an i after mysql. Ex: mysqli_connect, mysqli_query, etc.
post #14 of 18
Thread Starter 
Code:
<script type="text/javascript">
function getDownload(str)
{
if (str=="")
  {
  document.getElementById("downloadsubid").innerHTML="";
  return;
  }

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }

else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("downloadsubid").innerHTML=xmlhttp.responseText;
    }
  }

xmlhttp.open("GET","getdownloadsubname.php?q="+str,true);
xmlhttp.send();
return true;
}
</script>

...

<form name="upload" method="post" enctype="multipart/form-data" action="downloads_upload_file_query.php">
                    <table width="100%">
                    <tr>
                            <td>
                                <select name="download_parent_id" onchange="getDownload(this.options[this.selectedIndex].value)">
                                <option value="">Select Catagory</option>
                                <?php
                                $sql = "SELECT * FROM downloads_parent ORDER BY download_parent_id ASC";
                                $result = mysql_query($sql);

                                while($rows = mysql_fetch_array($result))
                                {
                                ?>
                                <option value="<?php echo $rows['download_parent_id']; ?>"><?php echo $rows['download_parent_name']; ?></option>
                                <?php
                                }
                                ?>
                                </select>
                                <br>
                                <div id="downloadsubid"></div>
                            </td>
                        </tr>
                        <tr>
                            <td class="page_text">File Name: <input name="download_name"><br /><br /></td>
                        </tr>
                        <tr>
                            <td class="page_text">File Author: <input name="download_author"><br /><br /></td>
                        </tr>
                        <tr>
                            <td class="page_text">File Location: <input type="file" name="file" id="file"><br /><br /></td>
                        </tr>
                        <tr>
                            <td><input name="Submit" type="submit" value="Upload"></td>
                        </tr>
                    </table>
                </form>
getdownloadsubname.php
Code:
<?php
include ('includes/sqlconnect.php');

$sql2 = "SELECT * FROM downloads_sub WHERE download_parent_id = " . $_GET["q"] . " ORDER BY download_sub_id ASC";
$result2 = mysql_query($sql2);

?>
<select name="downloads_sub_id">
<option>Select Sub Catagory</option>
<?php

while($rows2 = mysql_fetch_array($result2))
{
?>
<option value="<?php echo $rows2['download_sub_id']; ?>"><?php echo $rows2['download_sub_name']; ?></option>
<?php
}
?>
</select>
Code:
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "<div class=\\"ucp_text\\">Return Code: " . $_FILES["file"]["error"] . "</div><br />";
}
else
{
echo "<div class=\\"ucp_text\\">Upload: " . $_FILES['file']['name'] . "</div><br />";

if (file_exists("*dir*" . $_FILES["file"]["name"]))
{
echo "<div class=\\"ucp_text\\">" . $_FILES["file"]["name"] . " already exists. Please rename the file and try again.</div>";
}
else
{
echo "<div class=\\"ucp_text\\">Type: " . $_FILES["file"]["type"] . "</div><br />";
echo "<div class=\\"ucp_text\\">Size: " . ($_FILES["file"]["size"] / 1024) . " Kb</div><br />";
echo "<div class=\\"ucp_text\\">Catagory: " . $_POST['download_parent_id'] . "</div><br />";
echo "<div class=\\"ucp_text\\">Sub Catagory: " . $_POST['download_sub_id'] . "</div><br />";
echo "<div class=\\"ucp_text\\">File Author: " . $_POST['download_author'] . "</div><br />";
$file = copy($_FILES["file"]["tmp_name"], "*dir*" . $_FILES["file"]["name"]);

//$sql = "INSERT INTO ** (download_parent_id, download_sub_id, user_id, download_name, download_author, download_location, download_date_time) VALUES ('" . $_POST['download_parent_id'] . "', '" . $_POST['download_sub_id'] "', '" . $_COOKIE['user_id'] . "', '" . $_POST['download_name'] . "', '" . $_POST['download_author'] . "', '/var/www/downloads/download_files/" . $_FILES["file"]["name"] . "', '" . date("M d/y h:i a") . "')";
//$result = mysql_query($sql);

echo "<div class=\\"ucp_text\\">Successful</div>";
echo "<a class=\\"ucp_text\\" href=\\"../acp/downloads_edit.php\\">Go to Download Control Panel --></a>";
print_r($_FILES);
}
}
                    ?>
No. This is all the code. No restrictions.
Edited by mrsmoke - 8/15/11 at 1:29pm
post #15 of 18
Thread Starter 
Any Suggestions?
post #16 of 18
Your PHP looks solid, and nothing is excluding the .rar file format, have you tried googling the issue?
post #17 of 18
Thread Starter 
I have been googling for days and I have tried so many different thing but nothing works.
post #18 of 18
Try making a page with just a form with one file upload thing, and a couple lines of PHP to upload the file somewhere.
If it works, you'll know the problem is in your code somewhere.

Also, have you tried checking your PHP error log?
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › Ajax/php respone problem