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____ - <?
-
function delete_file(){
-
$tempo = array ("+30 minutos", "+1 hora");
-
echo '<select name="tempo">';
-
foreach ($tempo as $key =>$value){
-
echo "<option id='select_expire' value=\"$key\" >$value</option>\n";}
-
-
echo'</select>';
-
}//ende of the function
-
-
//call the form taga:
-
echo '<label for="select_expire">Escolhe o expire time:</label>';
-
//call the function
-
delete_file();
-
-
?>
_And this is my code so far, but obviously with many mistakes______ - <?
-
if (isset($tempo['30 minutes'])){
-
$file = $user_file;
-
$expire = $time + 30;
-
$time = time();
-
unlink($file);}
-
?>
4 2787
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...
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. - <?
-
setcookie("cookie[one]","cookieone", time() - 1800);
-
setcookie("cookie[two]","cookietwo");
-
-
if (isset($_COOKIE["cookie"])) {
-
-
foreach ($_COOKIE["cookie"] as $name =>$value)
-
echo '<select name="cookie">';
-
-
{
-
-
echo "<option id='select_expire' value=\"$name\" >$value</option>\n";}
-
-
echo'</select>';
-
}//ende of the function
-
-
//call the form:
-
echo '<label for="select_expire">Escolhe o expire time:</label>';
-
//call the function
-
?>
Any help?
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...
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, -
-
<?php
-
-
$link = @mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
-
$database = mysql_select_db(DB_NAME);
-
$sql = "SELECT * FROM temp WHERE DATE_ADD(time, INTERVAL 30 MINUTE) < NOW()";
-
$result = mysql_query("$sql");
-
while ($out = mysql_fetch_array($result)) {
-
$dirname = $out['directory'];
-
$filename = $out['filename'];
-
-
$file = "$dirname/$filename";
-
-
if(file_exists($file))
-
unlink($file);
-
-
rmdir($dirname);
-
-
$link = @mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
-
$database = mysql_select_db(DB_NAME);
-
$sql = "DELETE FROM temp WHERE directory = '$dirname'";
-
mysql_query("$sql");
-
}
-
-
mysql_close($link);
-
-
?>
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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);
|
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)){
|
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.
|
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
| |
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...
|
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>";
|
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...
|
by: Coffee Pot |
last post by:
Thanks for any advice.
~ CP
|
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
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |