RE: Substr function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for this George. I found a way to grab the file size of the
document and enter it in the DB as either KB or MB

$documentsize = $_FILES['thefile']['size'];
		
		       // if document size is less than 1MB round up
number to nearest KB
			   if ($documentsize <= 1048576) {

			   $documentsize = $documentsize / 1024;

			   $documentsize = round($documentsize);	
			   $documentsize .= "KB";		      
			   }
			   
			   // if document size is greater than 1MB round
up number to MB with 2 decimals
			   else {
			   $documentsize = $documentsize / 1048576; 
			   $documentsize = round($documentsize, 2);	
			   $documentsize .= "MB";		   
			   }
		


This might be useful for someone if they want to show the link to an
uploaded document with file size information displayed.

Steven



-----Original Message-----
From: George Pitcher [mailto:george.pitcher@xxxxxxxxxxx] 
Sent: 14 December 2004 13:50
To: S.D.Price
Subject: RE:  Substr function


Steven,

You need to start by checking what might be passed. I assume that you
going to work on 'name'. What will that be and will it always be
consistent? Will all files have three character extensions (mine
don't!)? If these are consistent, then you can use
substr($name,0,strlen($name)-4) to provide the name element and
substr($name,strlen($name)-3),3) to provide the extension, but i think
that explode() is better.

$name = "filename.pdf";
$split = explode(".",$name);
$fname = $split[0];
$extn = $split[1];


That might help you.

Cheers

George

> -----Original Message-----
> From: S.D.Price [mailto:S.D.Price@xxxxxxxxxx]
> Sent: 14 December 2004 1:41 pm
> To: php windows
> Subject:  Substr function
>
>
>
>
> Hi can anyone explain to me how to manipluate strings. I have 
> generated a file name
>
> ($_FILES['documenturl']['name'])
>
> Out of this server variable I need to grab the file and the extension 
> and put them into seperate fields for database upload. Any idea how to

> do this by using substr?
>
> Thanks
> Steven
>
>
>
>
>
>
>
>

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux