• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

PHP help!

OriginXT

New Member
1) How to upload from a remote server

2) How to find the file size of any file, for example an image

Thanks in advance!
 
1)
PHP:
<html>
<head>
<title>File Upload</title>
</head>
<?php
$f_dir = "/your/dir/";
$f_url = "your.web.site.com";
if ( isset( $fupload ) ) {
print "path: $fupload<br>\n";
print "name: $fupload_name<br>\n";
print "size: $fupload_size<br>\n";
print "type: $fupload_type<br>\n\n";

if ( $fupload_type == "image/gif" ) { // or whatever you want it to be
copy ( $fupload, "$f_dir/$fupload_name") or die ("Failed");

print <img src=\"$f_url/$fupload_name\"><p>\n\n";
}
}
?>
<body>
<form enctype="multipart/form-data" action="<?php print $PHP_SELF; ?>" method="POST">
<input type=hidden name="MAX_FILE_SIZE" value="51200">
<input type=file name="fupload"><br>
<input type=submit value="Upload>>">
</form>
</body>
</html>

2)
PHP:
print "$file is.. ";
print filesize( $file );

So the url would be like this-> http://www.site.com/filesize.php?file=index.php



Easy, hope I helped
 
another way of limiting file size instead of using
<input type="hidden" name="MAX_FILE_SIZE" value="51200">
from the form, you can do
PHP:
$maxfilesize = "51200";
if ($fupload_size <= $maxfilesize)
{ copy ( $fupload, "$f_dir/$fupload_name") or die ("Failed"); }
else { print ("Max file size exceeded");}
 
those predefined vars will only work if you have register globals on. you can also use $_FILE['userfile']['name']
that will give you the name of the file.
 
Back
Top