Page 2 of 2

Re: Image Resizing and File Uploading

Posted: Wed Feb 13, 2008 11:47 am
by zsines
Here is our connect.php file:

Code: Select all

 
require_once "DB.php";
 
# parameters for connecting to the "internDB" database
    $driver = "mysqli";
    $user = "";
    $password = "";
    $host = "localhost";
    $db = "internDB";
# DSN constructed from parameters
    $dsn = $driver . "://" . $user . ":" . $password . "@" . $host . "/" . $db ;
    
    
#Establishes connection to the Database
    $conn =& DB::connect ($dsn);
    
    if (DB::isError ($conn))
        include ('database/database.php');
 
        
$conn->setFetchMode (DB_FETCHMODE_ASSOC);
 
database.php is the script that builds our database on the fly. There are no errors with it.

Re: Image Resizing and File Uploading

Posted: Wed Feb 13, 2008 11:55 am
by liljester
zsines,

can you post your "fileUpload.php" in its entirety? it shows an error on line 140, and id like to see exactly where that is. the error thats being thrown is a database error, so I cant yet rule out any of your database code without seeing it. we have to find out why the mysqli is throwing an error.

Re: Image Resizing and File Uploading

Posted: Wed Feb 13, 2008 11:57 am
by zsines
Here you go. Enjoy

Code: Select all

 
<?php
 
session_start();
header("Cache-control: private"); // IE 6 Fix.
include "includes/connect.php";
 
/*if ($_SESSION["school"] != true) {
    session_unset();
    session_destroy();
    echo "<script>window.location = 'logout.php'</script>";
}*/
$_SESSION["notverified"] = false;
 
if($_SESSION["verified"] == false){
    $_SESSION["notverified"] =  true;
    echo "<script>window.location = 'home.php'</script>";
    session_unregister ("signUp"); 
    }
 
$check = true;
$filePresent = true;
$count = 0;
 
//DELETE THE FILE IF SELECTED
 
if(isset($_POST["deleteSelected"]))
{
    $data = $conn->query("SELECT * FROM files");
    while($row = $data->fetchRow())
    {
        if(isset($_POST["delete".$row["ID"]]))
        {
            $query = "DELETE FROM user_files WHERE file_ID = '".$row["ID"]."'";
            $conn->query($query);
            $query2 = "DELETE FROM files WHERE ID = '".$row["ID"]."'";
            $conn->query($query2);
        }
    }
}
if (isset($_POST["create"])) {
 
    $agree = $_POST["agree"];
    
    if($agree == "yes") {
        
        $agreeCheck = "Y";
    }
    else {
        
        $agreeCheck = "N";
    }
    
    $target_path = $sql;
    $target_path = $target_path . basename( $_FILES['fileUpload']['name']);  
    $fileName = $_FILES['fileUpload']['name'];
    $tmpName  = $_FILES['fileUpload']['tmp_name'];
    $fileSize = $_FILES['fileUpload']['size'];
    $fileType = $_FILES['fileUpload']['type'];
    $date = date('m-j-y');
    
    if($fileName == "") {
        $check = false;
        $error .= "<div id='error'>You must enter a valid file location.</div>";
    }   
    
    if($size > 10000000) {
        $check = false;
        $error .= "<div id='error'>File is too big. Please keep files less than 10 MB in size.</div>";
    }
    if($check == true) {
    
        $handle = fopen($tmpName, 'rb');
        $content = fread($handle, filesize($tmpName));
        $content = addslashes($content);
        fclose($handle);
        
        $fileName = addslashes($fileName);
        
        if($_SESSION["supervisor"] == true){
            $sql = "INSERT INTO files (form, agree, content, name, size, date, type) VALUES ('N', '$agreeCheck', '$content', '$fileName', '$fileSize', '$date', '$fileType')";
            $runSql = $conn->query($sql);
        }
        else {
            $sql = "INSERT INTO files (form, agree, content, name, size, date, type) VALUES ('N', 'N', '$content', '$fileName', '$fileSize', '$date', '$fileType')";
            $runSql = $conn->query($sql);
        }
        
        $userIDQuery = "SELECT * FROM user WHERE system_name = '" . $_SESSION["username"] . "'";
        echo $userIDQuery;
        $queryUserID = $conn->query($userIDQuery);
        $rowUser = $queryUserID->fetchRow();
        
        //check if the process worked
        $checkSql = "SELECT * FROM files WHERE name = '" . $fileName . "'";
        $queryCheck = $conn->query($checkSql);
        $resultCheck = $queryCheck->numRows();
        $row = $queryCheck->fetchRow();
        
        if($resultCheck != 1) {
            
            $error = "<div id='error'>An error occured during the upload process, please try again later.</div>";
        }
        else {
    
            $insertID = "INSERT INTO user_files (user_ID, file_ID) VALUES ('" . $rowUser['ID'] . "', '" . $row['ID'] . "')";
            $queryInsert = $conn->query($insertID);
            
            $success = "<div id='success'>File uploaded successfully.</div>";
        }
    }
}
 
//Make the FILE Table
    
$fileQuery = "SELECT * FROM files ORDER BY ID";
$query = $conn->query($fileQuery);
while($resultFiles = $query->fetchRow()){
    if($resultFiles['size'] > 1000000)
        $sizeMB = number_format($resultFiles['size']/1024/1024,2) + " MB";
    else
        $sizeMB = number_format($resultFiles['size']/1024,2) . " KB";
        
    $ID = $resultFiles["ID"];
    $delete = $ID;
    
    if($count%2 ==0){
        $bgcolor = "#CCCCCC";
    }
    else {
        $bgcolor = "#F7F7F7";   
    }
    $tableListing .= "<tr bgcolor='$bgcolor'>               
                        <td><span id='fileText'><input type='checkbox' name='delete$delete'></span></td>
                        <td><span id='fileText'>".$resultFiles['name']."</span></td>
                        <td><span id='fileText'>".$sizeMB."</span></td>
                        <td><span id='fileText'>".$resultFiles['date']."</span></td>";
                    
    if($_SESSION["supervisor"] == true) {   
        $tableListing .= "<td><span id='fileText'>".$resultFiles['agree']."</span></td>             
                         </tr>";
    }
    
    $count++;
}
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>File Upload</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" href="styles/main.css" type="text/css" />
    <link rel="stylesheet" href="styles/borders.css" type="text/css" />
    <?include ("content/icon.htm") ?>
</head>
<body class="image">
    <div id="centerContent">
        <div id="formAgreement">
            <!-- Page Header -->
            <h1>File Upload</h1>
            <span id="direction">
                This page is for uploading a previously created Internship Paperwork (Agreements, Contracts, Evaluations, etc.).
            </span>
            <br><br><br>
            
            <!-- Form to upload the Agreement/Contract Form -->
            <form name="form" method="post" action="fileUpload.php" enctype="multipart/form-data">
                
                <!-- Upload portion -->
                <span id="directionAgree">
                    Upload your File here (Limit 10MB):
                </span>
                <br><br>
                
                <input type="hidden" name="MAX_FILE_SIZE" value="10000000">
                <input type="hidden" name="action" value="upload">
                <input type="file" size="24" id="fileUpload" name="fileUpload" />
                <br><br><br>
                
                <? if($_SESSION["supervisor"] == true){?>
                <!-- I agree/disagree Portion -->
                <span id="directionAgree">
                    Would you like to display an "I Agree" or "I Disagree" option at the base of the 
                    viewable page?
                </span>
                <br><br>
                
                <span id="checkboxLabel">
                    Yes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>
                <input type="radio" name="agree" value="yes" />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <span id="checkboxLabel">
                    No&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </span>
                <input type="radio" name="agree" value="no" />
                <br><br>
                <?}?>
                
                <!-- This section is where the Submit and Reset buttons are placed -->
                <div id="submitArea">
                    <br>
                    
                    <?=$success?><?=$error?>
                    <br>
                    
                    <input type="submit" name="create" id="create" value="Submit Agreement" />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="reset" name="reset" id="reset" value="Reset Page" />
                    <br><br>
                    
                </div>
            <!-- End of Form -->
            
            <?php if($filePresent == true){?>
            <br><hr><br>
            <table width="50%" border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" align="center">
                <tr bgcolor="#1C3764">
                    <td width="5%"><span id="fileLabel">--</span></td>
                    <td width="45%"><span id="fileLabel">Filename</span></td>
                    <td width="15%"><span id="fileLabel">Size</span></td>
                    <td width="15%"><span id="fileLabel">Date</span></td>
                    <? if($_SESSION["supervisor"] == true){?>
                        <td width="10%"><span id="fileLabel">Agreement</span></td>
                    <?}?>
                </tr>
                <?=$tableListing?>
            </table>
            <br><input type="submit" name="deleteSelected" value="Delete Selected">
            <?}?>
            
            </form>
 
        </div>
    </div>
    <div id="topcontent"><?include ("content/north.php")?></div>
    <div id="leftcontent"><?include ("content/west.php")?></div>
    <div id="rightcontent"><?include ("content/east.php")?></div>
    <div id="bottomcontent"><?include ("content/south.php")?></div>
</body>
</html>
 

Re: Image Resizing and File Uploading

Posted: Wed Feb 13, 2008 2:47 pm
by liljester
are you using PDO? or are you using some 3rd party database abstraction layer?

Re: Image Resizing and File Uploading

Posted: Wed Feb 13, 2008 3:28 pm
by zsines
We are using PHP 5 and PEAR. We also have AJAX, but that is not on this page.

Re: Image Resizing and File Uploading

Posted: Thu Feb 14, 2008 8:01 am
by liljester
I must apologize, I have no experience with PEAR at all... at this point all I can tell you is that from the error youre getting, it would appear that youre trying to improperly use a database object method (a method returning an error object instead of a result set or somesuch). You could verify by remarking out the database call in question, and see if your script runs further.