Jump to content

GrizNeT

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Posts posted by GrizNeT

  1. Hi,

    I have searched about Cron in the net.. Cron is the name of program that enables unix users to execute commands or scripts (groups of commands) automatically at a specified time/date. Im guessing it can also execute php scripts? Please shed some light on me..

    Thanks!
  2. Hi Guys,

    How can i make a reservation email ticket expire? lets say for 5 days.. after 5 days if the user have not yet confirmed its status, his data will be automatically remove from the database..

    My setup im using MySQL 5 and PHP 5.

    Thanks in advance!
  3. Hi gmwebs :D

    The script works only if a file does exists and it matches the result of the file_exists() function. Then it will delete the existing file and upload the new one...

    My problem here is:

    What if there is an existing file pic1.jpg and i want to upload pic1.gif... Using the file_exists() function it will not surely find the pic1.jpg since im uploading pic1.gif.. The result here is that i have 2 files in my directory. What i want is i will only have one file with pic1.jpg(existing) be deleted and be replaced by pic1.gif..
  4. Hi to all,
    I have scanned most of the forum and found that most of the questions related to my problem is focused on [i]uploading a file and not to overwrite it but to create a new one[/i].
    My problem is a little bit different.

    [b]First[/b], any uploaded file is renamed according to the users name and concatenated by the extension that they are using. Please take note that they can only upload 1 file and it will recieve .jpg,gif,png extensions only..

    ex. (demouser.jpg or demouser.gif or demouser.png)

    [b]Second[/b], when the same user uploaded another file it will first check if a file is existing, if a file exists then it will [b]unlink/delete [/b] the file and upload the new file and if no file exists then it will upload the file.

    My problem here is the [b]second one[/b].. i have trouble finding if a file is existing. i know im a bit closer but i need your help guys. Many thanks

    Here is my code:

    [code]
    <html>
    <head>

    <?php
    require_once('includes/config.inc');
    require_once('includes/constants.php');
    require_once('includes/functions.php');
    require_once('includes/mysql_connect.php');



    session_start(); //Start session
    $myid =  $_SESSION['myid'];

    $query = "SELECT cli_name FROM tblclients WHERE cli_id = $myid";
    $result = @mysql_query($query);
    $row = mysql_fetch_array($result);

    $myname = $row[0];


    ?>
    <title>File Uploader </title>
    </head>
    <body>
    <h1>Uploading file...</h1>
    <?php
    if ($_FILES['userfile']['error'] > 0)
    {
    echo 'Problem: ';
    switch ($_FILES['userfile']['error'])
    {
    case 1: echo 'File exceeded upload_max_filesize'; break;
    case 2: echo 'File exceeded max_file_size'; break;
    case 3: echo 'File only partially uploaded'; break;
    case 4: echo 'No file uploaded'; break;
    }
    exit;
    }

    //Check for correct MIME type
    if ($_FILES['userfile']['type'] =='image/pjpeg')
    {
    $ext = ".jpg";
    }
    elseif ($_FILES['userfile']['type'] =='image/gif')
    {
    $ext = ".gif";
    }
    elseif ($_FILES['userfile']['type'] =='image/png')
    {
    $ext = ".png";
    }
    else
    {
    echo 'Problem: file is not an image';
    exit;
    }



    //Check if file exists
    $myfile = '/var/www/html/ecrema/uploads/logos/'.$myname.$ext;
    $mydir = '/var/www/html/ecrema/uploads/logos/';



    if (file_exists($myfile))
    {

    unlink($myfile);
    //Change the filename to Company's Name + logo
    $_FILES['userfile']['name']  = $myname.$ext;

    //Put the file where ur directory is located
    $upfile = $mydir.$_FILES['userfile']['name'];
    //echo $upfile.'<br />';
    }
    else
    {

    //Change the filename to Company's Name + logo
    $_FILES['userfile']['name']  = $myname.$ext;

    //Put the file where ur directory is located
    $upfile = $mydir.$_FILES['userfile']['name'];
    //echo $upfile.'<br />';
    }

    if (is_uploaded_file($_FILES['userfile']['tmp_name']))
    {
    if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile))
    {
    echo 'Problem: could not move file to destination directory';
    exit;
    }
    }
    else
    {
    echo 'Problem: Possible file upload attack. Filename: ';
    echo $_FILES['userfile']['name'];
    exit;
    }

    echo 'File uploaded sucessfully<br /><br />';


    ?>
    </body>
    </html>
    [/code]
×
×
  • 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.