Will this work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
chris98
Forum Contributor
Posts: 103
Joined: Tue Jun 11, 2013 10:47 am
Location: England, United Kingdom

Will this work?

Post by chris98 »

OK, I've created the following, but am unsure whether it will work correctly, and since it's exceptionally hard to get the file uploading on my server to function correctly, I thought I'd ask here to make sure it works properly first.

When a file uploads, it first inserts the data into the database and then uploads the file to avoid the "MySQL Server has gone away" error, my timeout is 30 seconds. My MAX_FILE_SIZE is 128 MegaBytes, so if it's a large file uploading I want to know if it is uploading and not finished - the primary reason for this is because the staff members who check the file will see the "X new files" when they login, based on the database. Since the file uploads last, it might not be on the server when they see the "X new files" so might delete the file thinking the file is corrupt. I would therefore like (if possible) for a way to check if files are uploading. If my way is not possible, could someone give me some other advice on what to do?

Thanks.

Code: Select all

<?php
if ($pun_user['downloads_moderator'] == '1' || $pun_user['g_global_moderator'] == '1' || $pun_user['g_id'] == PUN_ADMIN)
{
	$uploading_files = '0';
	$uploaded_files = '0';
	$admmod = $shn_sites->prepare("SELECT COUNT(*) AS id FROM downloads_unchecked");
	$admmod->execute();
	$count = $admmod->fetch();

	$admmod = $shn_sites->prepare("SELECT file FROM downloads_unchecked");
	$admmod->execute();
	foreach ($admmod as $row)
	{
		while (!file_exists('/home/**DIRECTORIES**/'.$row['file'].''))
		{
			$uploading_files = $uploading_files + 1;
		}
		
		while (file_exists('/home/**DIRECTORIES**/'.$row['file'].''))
		{
			$uploaded_files = $uploaded_files + 1;
		}
		
	}	
	?>		
<div class="boxed">
<h2 class="heading">Admin</h2>
			<div class="content">
				<ul>
				<?php 
		if ($count['id'] > 0)
		{
?>
<li class="first"><a href='http://admin.mysite.com/'><?php echo $uploaded_files; ?> New Files</a></li>
<?php 
		}
		else
		{
?>
<li class="first"><a href='http://admin.mysite.com/'>No New Files</a></li>
<?php
		}
 

	$admmod2 = $shn_sites->prepare("SELECT COUNT(*) AS id FROM downloads WHERE approval = '1'");
	$admmod2->execute();
	foreach ($admmod2 as $row)
	{	
	
		if ($row['id'] > 0)
		{
?>					
<li><a href="http://admin.mysite.com/updated_files.php"><?php echo $row['id']; ?> Updated Files</a></li>
<?php 
		}
		else
		{
?>
<li><a href="http://admin.mysite.com/updated_files.php">No Updated Files</a></li>
<?php
		}

	}
	
		if ($uploading_files > 0)
		{
?>					
<li><strong><?php echo $uploading_files; ?>&nbsp;Files Currently Uploading</strong></li>
<?php 
		}
		else
		{
?>
<li>No Files Currently Uploading</li>
<?php
		}

?>

				</ul>
			</div>
		</div>
<?php 
} 

?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Will this work?

Post by requinix »

Does your thinking change much if I mention that file uploads happen before your code even begins? By the time your script gets around to connecting to the database, the file has already been uploaded and stored in the temporary location.
User avatar
chris98
Forum Contributor
Posts: 103
Joined: Tue Jun 11, 2013 10:47 am
Location: England, United Kingdom

Re: Will this work?

Post by chris98 »

Sorry, I forgot to mention that this is in a separate file, it's part of the sidebar menu displayed on every page so it won't be effected by the MySQL timeout.
User avatar
chris98
Forum Contributor
Posts: 103
Joined: Tue Jun 11, 2013 10:47 am
Location: England, United Kingdom

Re: Will this work?

Post by chris98 »

I also originally created it for large files near 128 MB because they take a while to upload, so would it work with a larger file?
Post Reply