Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Need filesize stored..

    Hi everyone,
    Im nearly finished with my modification to my website,
    but have a problem so if anyone can help it would be very usefull.
    The script is:

    PHP Code:
    <?php
    include "admin/config.php";
    include 
    "./conn.php";
    include 
    "./functions.php";

    if(isset(
    $_POST['url']))
    {
        
    $url $_REQUEST['url'];
        
    $upload_file_name explode("/"$url);
        
    $upload_file_name $upload_file_name[count($upload_file_name) - 1];

        
    $_SESSION['key'] = randomNumber();
        
    $strSql "select * from ".DB_TABLE_PREFIX."files where `key` = '".$_SESSION['key']."'";
        
    $rsChkKey $conn->execute($strSql);
        if(!
    $rsChkKey->EOF)
        {
            while(
    $rsChkKey->fields['key'] == $_SESSION['key'])
            {
                
    $strSql "select * from ".DB_TABLE_PREFIX."files where `key` = '".$_SESSION['key']."'";
                
    $rsChkKey $conn->execute($strSql);
                
    $_SESSION['key'] = randomAlphaNumeric(8);
            }
        }
        
    $_SESSION['delete_key'] = randomNumber();
        
    $strSql "select * from ".DB_TABLE_PREFIX."files where `delete_key` = '".$_SESSION['delete_key']."'";
        
    $rsChkKey $conn->execute($strSql);
        if(!
    $rsChkKey->EOF)
        {
            while(
    $rsChkKey->fields['key'] == $_SESSION['key'])
            {
                
    $strSql "select * from ".DB_TABLE_PREFIX."files where `delete_key` = '".$_SESSION['delete_key']."'";
                
    $rsChkKey $conn->execute($strSql);
                
    $_SESSION['delete_key'] = randomAlphaNumeric(8);
            }
        }
        
    $newfilename $upload_file_name;//$_FILES["fupload"]["name"];
        
    $newfilename preg_replace('/\s+/'' '$newfilename);
        
    $newfilename ereg_replace(" ","_",$newfilename);
        
    $newfilename ereg_replace("[^a-z,A-Z,0-9,_.]","_",$newfilename);
        
    $newfilename preg_replace('/\_+/''_'$newfilename);
        if(
    strlen($newfilename)>62)
        {
            
    // Truncate to 65 characters.
            
    $filename_array_dot explode("."$newfilename);
            
    $filename_array_count count($filename_array_dot);
            
    $ext  $filename_array_dot[$filename_array_count-1];
            
    $newfilename substr($newfilename,0,(65-strlen($ext+1)));
            
    $newfilename $newfilename.".".$ext;
        }
        
        
    $rConfig $conn->execute("select * from ".DB_TABLE_PREFIX."server_config where active=1 ORDER BY RAND() LIMIT 0,1");
        
    $file_url $rConfig->fields['server']."/cmd.php?do=upload&url=".$url."&name=$newfilename";
        
    //die($file_url);
        
    $tmp fopen($file_url"r");
        
    $status fread($tmp10);
        
    fclose($tmp);
        
    $upload $status == "success";
        if(!
    $upload
        {
            echo 
    "error in uploading...";
        } 
        else 
        {
            
    //-------------------------------------------------
            //file was copied... now remove the temp file
            
    @unlink($upload_temp_path.'/'.$upload_file_name);
            
    //-------------------------------------------------
            
    $strSql "INSERT INTO `".DB_TABLE_PREFIX."files` (
            `fileid` , `key`, `delete_key` , `mailto` , `mailfrom` ,
            `mailmessage` , `filename` , `foldername`, `filesize` , `uploadtime` ,
            `ip`, `downloads`)  VALUES (
            '', '"
    .$_SESSION['key']."',
            '"
    .$_SESSION['delete_key']."',
            '"
    .$_REQUEST['mailto']."',
            '"
    .$_REQUEST['mailfrom']."',
            '"
    .$upload_file_desc."',
            '$newfilename',
            '"
    .$rConfig->fields['server']."',
            '"
    .$file_size."',
            '"
    .time()."',
            '"
    .$_SERVER['REMOTE_ADDR']."',
            '0'
            )"
    ;
            
    $conn->execute($strSql);
            echo 
    'Successfully uploaded the file!<br>';
            echo 
    SITE_URL."/line/".$_SESSION['key']."/".$newfilename.".html"
        }
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Eskick Uploader</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="../style.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
    <tr valign="top">
    <td><div align="center" class="Heading">Eskick Topsecret Uploader</div></td>
    </tr>
    <tr valign="top">
    </tr>
    <tr valign="top">
    <td>
    <div align="center">
    <p align="center"><br>
    <span class="smallBoldHeading">Uploader </span></p>
    <form action="topsecret.php" method="post">
    <table width="500" border="0" cellspacing="1" cellpadding="3">
    <tr>
    <td align="center">Url: <input style="width: 300px;" type="text" name="url"> <input type="submit" value="Upload"></td>
    </tr>
    </table>
    </form>
    </div>
    </body>
    </html>
    and the cmd.php is
    PHP Code:
    <?php
    $store_dir 
    "----FILEFOLDER---";

    function 
    get_param($name)
    {
        
    $value "";
        if(isset(
    $_GET[$name])) $value $_GET[$name];
        if(isset(
    $_POST[$name])) $value $_POST[$name];
        return 
    $value;
    }

    $cmd get_param("do");
    if(
    $cmd == "upload")
    {
        
    $path get_param("url");
        
    $file_name get_param("name");
        
        
    $file=fopen("$store_dir/$file_name""w+");
        
    $ch curl_init($path);
        
    curl_setopt($chCURLOPT_FILE$file);
        
    curl_setopt($chCURLOPT_HEADER0);
        
        
    curl_exec($ch);
        
    curl_close($ch);
        
    fclose($file);
        
    chmod("$store_dir/$file_name"0777);
        echo 
    "success";
    }
    else if(
    $cmd == "download")
    {
        
    $file_name get_param("name");
        
    $fp fopen("$store_dir/$file_name""r");
        while (!
    feof($fp))
        {
          echo 
    fread($fp8192);
        }
        
    fclose($fp);
    }
    else if(
    $cmd == "delete")
    {
        
    $file_name get_param("name");
        if(
    file_exists("$store_dir/$file_name"))
            
    unlink("$store_dir/$file_name");
        echo 
    "success";
    }
    else
    {
        echo 
    "error";
    }
    Basicly, i need the script to store the filesize too, unfortunatly it fails to do so although the script works,
    "filesize" is the row name,

    Any help welcome

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,169
    Thanks
    19
    Thanked 65 Times in 64 Posts
    Where are you setting $file_size? I don't see if anywhere in the code you've posted - which would explain why it isnt working.

    http://www.php.net/filesize

  • #3
    New Coder
    Join Date
    Nov 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah thats the problem, i dont have it, Could anybody help?

  • #4
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts

  • #5
    New Coder
    Join Date
    Nov 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah iv seen that ages ago, I dont know how to complete it, Could anybody help with an updated code?

  • #6
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    I think the PHP manual explains it pretty straight forward, but here:

    PHP Code:
    $file_size filesize('NAME OF FILE HERE'); 
    Not much more we can give you than that

  • #7
    New Coder
    Join Date
    Nov 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, but does that work with urls?

  • #8
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    I don't know, why don't you try it?

    Somewhere in there you already have the filename set to a variable, at which point you only need to put the variable in the brackets. So you should only need to identify the correct variable and drop this code in after that variable is set, and before you are trying to use $file_size.

    PHP Code:
    $file_size filesize($filenamevariable); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •