473,513 Members | 2,881 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unlink() file

5 New Member
Hi everybody!
Im having trouble doing this task hope someone could help.

I still working on my project/app where user can upload a file a server, that then provide him with the link that can be shared for a certain period of time.
I want, using <option> tag, to make a user select the max time that he would like to share the image. For example when the user select 30 minutes, the php file get the server time, and then plus 30 minutes unlink/delete the file from database. (thats my idea). Im having problem with it.

I leave you with this code so far! The problem its obvious on time function.

_Display the option____

Expand|Select|Wrap|Line Numbers
  1. <?
  2. function delete_file(){
  3.     $tempo = array ("+30 minutos", "+1 hora");
  4.     echo '<select name="tempo">';
  5.     foreach ($tempo as $key =>$value){
  6.         echo "<option id='select_expire' value=\"$key\" >$value</option>\n";}
  7.  
  8.     echo'</select>';
  9. }//ende of the function
  10.  
  11.     //call the form taga:
  12.     echo '<label for="select_expire">Escolhe o expire time:</label>';
  13.     //call the function
  14.     delete_file();
  15.  
  16. ?>

_And this is my code so far, but obviously with many mistakes______

Expand|Select|Wrap|Line Numbers
  1. <?
  2. if (isset($tempo['30 minutes'])){
  3.     $file = $user_file;
  4.     $expire = $time + 30;
  5.     $time = time();
  6.     unlink($file);}
  7. ?>
Jan 12 '10 #1
4 2787
dgreenhouse
250 Recognized Expert Contributor
First, the delete logic should be uncoupled from the form logic.

Probably running a cron job every 5 minutes or so...

I'd just have the image file names and expiry times inserted into a database.

Then, when the cron job runs, it checks the "sharing" table looking for expirations and deletes those files it finds that should be expired.

A better; and more complex, design wouldn't delete the files at all, but only share them if they're still within the sharing period. In addition, the app could allow the 'sharing user' to elect to either delete the image upon expiration or just un-share it. That way, the ‘sharing user’ could elect to share it again at a later date. Using this logic, it would be easy to extend the application further to allow the 'sharing user' to give specific '"share-ee" users' access to the images. Obviously, you can extend this ad-infinitum - but that's the joy of 'over engineering!' ;-)

I'm not sure of your complete design criteria here, but having it coupled to a form ensures it will not get run until someone accesses the form.

Or, maybe I'm missing something...
Jan 13 '10 #2
kelvinwebdesigner
5 New Member
Thanks for the help.
But later i figure it out! maybe using setcookie would be better!

So i came up with this code. But for some reason is not working, as well as option select.

Expand|Select|Wrap|Line Numbers
  1. <?
  2. setcookie("cookie[one]","cookieone", time() - 1800);
  3. setcookie("cookie[two]","cookietwo");
  4.  
  5. if (isset($_COOKIE["cookie"])) {
  6.  
  7. foreach ($_COOKIE["cookie"] as $name =>$value)
  8. echo '<select name="cookie">';
  9.  
  10. {
  11.  
  12.         echo "<option id='select_expire' value=\"$name\" >$value</option>\n";}
  13.  
  14.     echo'</select>';
  15. }//ende of the function
  16.  
  17.     //call the form:
  18.     echo '<label for="select_expire">Escolhe o expire time:</label>';
  19.     //call the function
  20. ?>
Any help?
Jan 21 '10 #3
dgreenhouse
250 Recognized Expert Contributor
Could you explain what you're trying to accomplish with this code.

As I mentioned in my last post, I think you're going about this the wrong way.
( I could be wrong and missing the obvious and simple.)

The sharing logic SHOULD not be tied to a FORM's logic in anyway; other than the expiration time being entered by the SHARING user.

Can you explain why you want to use a form?

Also...

How are the proposed images that are to be shared presented to users?

What is this to be used for? Is this an actual application, a school project, or just a personal project?

I realize that the program logic in your initial post is quite simple, it's just that I don't think you've provided enough information to help you.

I guess you could use the logic you described and base the expiration time off of the time the (file was / files were) uploaded to the server, but where are you going to store the expiration time?

Is it 30mins, an hour, etc.?
If the time is going to be in a cookie and it is of variable in length - then - who's cookie?

I hope I'm making sense...
Jan 21 '10 #4
kelvinwebdesigner
5 New Member
Hi dgreenhouse, this post is a continuation of the first one where i did the introduction of this application! fortunately i solved the problems that i has with headers last time. So check it out!

http://bytes.com/topic/php/answers/8...l-header-error

Maybe you're missing something! The thing is the user upload the photo, and choose for how long he wants to use the service! In case he chooses 30 minutes, the file will be deleted in that time, and the link will be no longer available.

Maybe i could do it just interracting with the database thus,

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4. $link = @mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
  5. $database = mysql_select_db(DB_NAME);
  6. $sql = "SELECT * FROM temp WHERE DATE_ADD(time, INTERVAL 30 MINUTE) < NOW()";
  7. $result = mysql_query("$sql");
  8. while ($out = mysql_fetch_array($result)) { 
  9.    $dirname = $out['directory'];
  10.    $filename = $out['filename'];
  11.  
  12.    $file = "$dirname/$filename";
  13.  
  14.    if(file_exists($file))
  15.    unlink($file);
  16.  
  17.    rmdir($dirname);
  18.  
  19.    $link = @mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
  20.    $database = mysql_select_db(DB_NAME);
  21.    $sql = "DELETE FROM temp WHERE directory = '$dirname'";
  22.    mysql_query("$sql");
  23. }
  24.  
  25. mysql_close($link);
  26.  
  27. ?>
  28.  
Jan 22 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
6678
by: Eric | last post by:
Hello, I created a form to upload files. The formfield contents are stored as records in an Ascii file "data.dat"; for reasons I am not using a MySql database. The upoaded file itself is stored in a directory called "files". With an administration form I can read all contents of the data.dat file and select records to delete (one at a...
1
3697
by: Bob Bedford | last post by:
I've tried everything seen on Internet, but nothing works: I'm trying to move a file from a dir to a subdir (WinXP Pro, Apache, PHP 4.3.3) Here is the code: chmod($XMLPath, 0777); chmod($XMLPath.$file, 0777); chmod($XMLPath.$successpath, 0777);
1
2782
by: Chamomile | last post by:
I am having trouble getting unlink() to work on my local machine (win 2000, Apache, php 4.2.2) when I invoke unlink() in order to change a file name during a 'picture edit' change from a form upload on my local machine using simple stuff like: <?php if(file_exists($new_file_name)){
10
7559
by: lorenzogordon | last post by:
Hi there, I'd greatly appreciate any insights into the following problem: I've got PHP running fine on IIS (OS: Server 2003, SP1; IIS: 6.0; PHP: 4.3.11). In PHP, the user uploads a file, which is then processed and the contents are inserted into a new file, created in PHP, onto the server.
6
16752
by: Benjamin | last post by:
Hello, I'm running PHP 5.2.0 as a Apache 2.2 server module. When, I try to unlink I get this: "Warning: unlink(file.txt) : Permission denied..." What and how do I change this so it works? Thanks
4
12809
by: nitinpatel1117 | last post by:
Hi I am trying to delete a csv file using the unlink() function, but i keep getting a permission denied warning Warning: unlink(UsedNOS200704191.CSV): Permission denied in E:\webroot\dev\file_test\index.php on line 416 My script basically reads email attachments and downloads the attachment file into the current directory of the running...
15
3731
by: Morteneistrom | last post by:
Im a complete n00b at PHP so please forgive me if this i a stupid question Why wont the following work. PHP Code: <?php foreach (glob('../images/profil/*.jpg') as $filename) { echo "$filename <br>". "<a href="unlink('$filename');">Delete</ a>";
11
4447
by: byteoart | last post by:
I'm a newbie to php. I am trying to delete a file from the server that I put there (one file, not the whole directory). I am using unlink ($filename); I did the path as a relative path as follows: .../images/6/image_001.JPG I did a scandir $files = scandir("../images/6"); The print_r ($files); shows that the file is one of the files...
18
14588
by: Coffee Pot | last post by:
Thanks for any advice. ~ CP
9
8408
code green
by: code green | last post by:
I have this piece of code to tidy up after a function that calls move_uploaded_file() if(file_exists($destination.$filename)) { $exitmsg .= "<br>File still in temporary location <br>$filename <br>Attempting deletion "; if(unlink($destination.$filename)) $exitmsg .= '<br>Success deleting. Please try again '; else
0
7269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7559
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5701
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.