Jump to content

Recommended Posts

Hi, ive written an application that allows employees to upload files into a database.

I am trying to implement code to stop the user from going beyond their database quota and thus have written this code

[code]
// does the file exceed that users file storage limit
$fsize = $_FILES['frmFile']['size'];
$fcurrent = $result['total'];
$totals = $fsize + $fcurrent;
if ($totals >= 1000000)
{
echo "Error, this file will exceed your total file size allowance";
echo "<p>" . '<a href="viewuploads.php">' . "View Uploads" . "</a></p>";
return; //a return here terminates the execution of this page.
}
/code]

This works fine, however I need to use the value from the database (i.e. each employee can have a different quota)

[code]
//query to select dbEmployeeQuota
$query2 = "select dbEmployeeQuota as quota from employee where dbEmployeeId='".$_SESSION['sessEmployee']['id']."'";
$equota = mysql_query($query2);
$a = mysql_fetch_array($equota, MYSQL_ASSOC);
$quota = $a['quota'];
[/code]

This gets the quota out of the database and when i [code]echo $quota;[/code] it displays 1000000.

Unfortunately when i try to use it in the IF statement..........
[code]if ($totals >= $quota)[/code]
OR
[code]if ($totals >= $quota = $a['quota'])[/code]

..........it still allows the file to be uploaded.

If anyone can help me it would be highly appreciated  ;D ;D ;D

Cheers guys[/code]
Link to comment
https://forums.phpfreaks.com/topic/33356-solved-problem-with-database-variable/
Share on other sites

Maybe php doesn't like the data types.  You could try this:

[code]<?php
// Get the limit from the database
$query = "SELECT dbEmployeeQuota AS quota, dbEmployeeCurrent AS current FROM employee WHERE dbEmployeeId='".$_SESSION['sessEmployee']['id']."'";
$equota = mysql_query($query);
$row = mysql_fetch_array($equota, MYSQL_ASSOC);
$quota = intval($row['quota']);
$current = intval($row['current']);

// does the file exceed that users file storage limit
$fsize = intval($_FILES['frmFile']['size']);
if (($fsize + $current) >= $quota){
  echo "Error, this file will exceed your total file size
  echo "<p>" . '<a href="viewuploads.php">' . "View Uploads" . "</a></p>";
  return; //a return here terminates the execution of this page.
}
?>[/code]

Notice that I've included the current quota in the sql query to the database, as I'm assuming this is where you're storing the information.  You just need to alter the column name to the one in your db table

Regards
Huggie
[quote author=joebudden link=topic=121527.msg499842#msg499842 date=1168272220]
there is no column "dbEmployeeCurrent" ----    Huggie
[/quote]

No, but if you want to check if a user is going over their quota, you must have the running total of what they're using stored somewhere right?

Huggie
hi, im back!!!

I see what ur sayin Huggie, but cant this just be done on the page???

Here is my code jesi

[code]<?php
// is there an uploaded file to insert?
if (isset($_FILES['frmFile'])) 
{
//query to calculate the total size of files in the database
$query = "select sum(size) as total from artefact where dbEmployeeId='".$_SESSION['sessEmployee']['id']."'";
$allowance = mysql_query($query);
$result = mysql_fetch_array($allowance, MYSQL_ASSOC);

// does the file exceed that users file storage limit
$fsize = $_FILES['frmFile']['size'];
$fcurrent = $result['total'];
$totals = $fsize + $fcurrent;

//query to select dbEmployeeQuota
$query2 = "select dbEmployeeQuota as quota from employee where dbEmployeeId='".$_SESSION['sessEmployee']['id']."'";
$equota = mysql_query($query2);
$a = mysql_fetch_array($equota, MYSQL_ASSOC);
$quota = $a['quota'];
echo $quota;

if ($totals >= $quota)
{
echo "Error, this file will exceed your total file size allowance";
echo "<p>" . '<a href="viewuploads.php">' . "View Uploads" . "</a></p>";
return; //a return here terminates the execution of this page.
}
?>


[/code]
[quote author=joebudden link=topic=121527.msg499859#msg499859 date=1168273172]
I see what ur sayin Huggie, but cant this just be done on the page???
[/quote]

Now you've posted your code, I can see you're using sum() to get the total size currently in use, so just use the code that I provided, only select one column, not the second one that I added.

Regards
Huggie
cheers for the help you guys but once again i must relinquish my dignity.....

after constructing a test page, i noticed that the value in my dbEmployeeQuota was 10mb and not 1mb, hence no error

my original code works fine

LOVE U HUGGIE AND JES!!!!!!!!! PLEASE DONT BAN ME FOR MY STUPIDITY!!!!!!!

[code]
<?php
// is there an uploaded file to insert?
if (isset($_FILES['frmFile'])) 
{
//query to calculate the total size of files in the database
$query = "select sum(size) as total from artefact where dbEmployeeId='".$_SESSION['sessEmployee']['id']."'";
//query to select dbEmployeeQuota
$query2 = "select sum(dbEmployeeQuota) as quota from employee where dbEmployeeId='".$_SESSION['sessEmployee']['id']."'";

$allowance = mysql_query($query);
$equota = mysql_query($query2);
$result = mysql_fetch_array($allowance, MYSQL_ASSOC);
$a = mysql_fetch_array($equota, MYSQL_ASSOC);

// does the file exceed that users file storage limit
$fsize = $_FILES['frmFile']['size'];
$fcurrent = $result['total'];
$totals = $fsize + $fcurrent;
$quota = $a['quota'];

if ($totals >= $quota)
{
echo "Error, this file will exceed your total file size allowance";
echo "<p>" . '<a href="viewuploads.php">' . "View Uploads" . "</a></p>";
return; //a return here terminates the execution of this page.
}
?>
[/code]

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.