...

View Full Version : Need filesize stored..



eskick
08-20-2007, 09:52 AM
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
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($tmp, 10);
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
$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($ch, CURLOPT_FILE, $file);
curl_setopt($ch, CURLOPT_HEADER, 0);

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($fp, 8192);
}
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 :)

NancyJ
08-20-2007, 11:55 AM
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

eskick
08-20-2007, 12:19 PM
Yeah thats the problem, i dont have it, Could anybody help?

Pennimus
08-20-2007, 12:21 PM
http://uk3.php.net/filesize

eskick
08-20-2007, 12:22 PM
Yeah iv seen that ages ago, I dont know how to complete it, Could anybody help with an updated code? :D

Pennimus
08-20-2007, 12:24 PM
I think the PHP manual explains it pretty straight forward, but here:


$file_size = filesize('NAME OF FILE HERE');

Not much more we can give you than that :thumbsup:

eskick
08-20-2007, 12:27 PM
Thanks, but does that work with urls?

Pennimus
08-20-2007, 12:32 PM
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.


$file_size = filesize($filenamevariable);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum