Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Download file blocker


  • Please log in to reply
3 replies to this topic

#1 oneplace2u


    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 04 October 2010 - 12:28 PM

I have membership on my website and members login in. The are able to download two files and add and make corrections on the files. Then they will upload the file back to the web site to the same directory. I have a problem with this, where I need to stop any member to download or upload this files until the member who download the file first uploads the file.
Here is my upload file. Have two files like this just different file name to upload.
// set your folder
// give write rights on that folder

$today = date("Y-m-d\TH:i:s");
$uploadfile =basename($_FILES['upload']['name']);
$filename = basename($_FILES['upload']['name']);
if ($_FILES['upload']['name']){

if (file_exists("$uploaddir/$uploadfile"))
rename("$uploaddir/$uploadfile","$uploaddir/$uploadfile + $today.bak");
if (move_uploaded_file($_FILES['upload']['tmp_name'], "$uploaddir/$uploadfile"))
//that mean upload is completed with success;
$msg = "Master 2000 thru 2005.xls has been uploaded, Thank you";
echo $msg;
//that mean upload faild;
$msg = "failed to upload, try again, if fails contact, webmaster@amour-rounds.com";
echo $msg;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My software - PHP Upload</title>
<body style="font-family:Arial; font-size:14px;">
<form name="addnews" enctype="multipart/form-data" method="post" action="phpupload.php">
<table border=2 cellspacing=1 cellpadding=4 align=center width=100% bgcolor="#000000">
<tr bgcolor="#FFFFFF">
<td width=121 valign="top" class="btext" height="28" align=right><div align="left"><b> Upload: Master 2000 thru 2005.xls</b></div></td>
<td valign="top" width=443><input type="hidden" name="MAX_FILE_SIZE2" value="6500000"/>
<input name="upload" type="file" size="60" style="font-family:Arial; font-size:14px;"></td>
<tr bgcolor="#FFFFFF">
<td valign="top" align="center" colspan="2">
<input type="submit" name="submit" value=" Submit " class="button">

Edited by Orjan, 04 October 2010 - 02:36 PM.
removed double code tags

  • 0

#2 SoN9ne


    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 118 posts
  • Programming Language:Java, PHP, JavaScript, Bash
  • Learning:C, Objective-C

Posted 05 October 2010 - 04:44 AM

There a many different ways to do what you want.

A simple way, off the top of my head, is to record the user ID that is checking out the file.
If a file has a checked_out user ID then the file cannot be downloaded.
Only the checked_out user ID can upload the file back to the server to release the lock.
During the upload process you could update the database to empty the checked_out user ID.

This was simple method you could use.
It will need some redundancies, for example, what would happen if the person who checked out the file never uploads a revised one?
This would mean that no one could download or modify this file since it would be locked. I'm not sure if you have a management section but it could be easily fixed by having a utility to empty the checked_out section in the db.

Hope this is a push in the right direction. It's early so my mind may be a little slow. ^^

Hope you find your solution.
  • 0
"Life would be so much easier if we only had the source code."

#3 oneplace2u


    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 05 October 2010 - 10:35 AM

Will I don't have the skills to write a program like that, I will have to find some one to do it for me.
  • 0

#4 bbqroast


    Codecall Addict

  • Senior Member
  • PipPipPipPipPipPip
  • 564 posts
  • Location:/etc/passwd

Posted 16 October 2010 - 09:55 PM

It wouldn't be hard i'd give you some pointers but when my PC got broken the Techies desided all my PHP and HTML stuff wasn't work releated and didn't save it.
All you need is to find a basic user tutorial in mysql. add a column in the file table (i recommend PHPMyAdmin) called "use" with a default of 0 and another called "useID".
Then when some one takes out a file get their user ID, set use to one and set useID to their ID. When a user downloads the file it will check if use is at one if it is then it will give a error if its at zero it will proceed normally.
Finally when the user checks in the file check they have the same ID as useID if so upload the new file and set use to 0.- Keep useID so you know who last editted it or you could make a "changes" table (ID,fileID,userID,date).
Happy scripting BBQ
  • 0
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).

Also tagged with one or more of these keywords: max_file_size

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download