[FX.php List] Upload script in PHP

Bob Patin bob at patin.com
Wed Mar 15 17:51:20 MST 2006


I finally got an upload script working and thought I'd share it here  
with the list. The trick turned out to be that I had to change the  
owner of the uploads folder on my OS X Server machine. Once I changed  
the owner to "www" the script worked perfectly.

-------------------------------------------------------------
<?php

if ($_FILES['userfile']['name'])
	{
	$filename=$_FILES['userfile']['name'];
	$err = false;
	$errMsg = '';
			
				
	//checks to see if the file is less than 50MB if not, error out
	if ($_FILES['userfile']['size'] > 50971520)
		{
		$err = true;
		$errMsg = 'The file you uploaded is larger than 50MB.';
		}
				
	//no errors reported above, then keep going
	if (!$err)
		{
     $path = '/Library/WebServer/Documents/longterm/uploads';
	$uploadfile = $path.'/'.$filename;
		//try to move the file. If this fails, you get false
		chmod($path, 0777);
		$uploadSuccess = move_uploaded_file($_FILES['userfile'] 
['tmp_name'], $uploadfile);
		if ($uploadSuccess){
		?>
<style type="text/css">
<!--
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
}
-->
</style>

<span class="style1">		The file named <strong><?php echo $filename; ? 
 ></strong> was successfully uploaded.
		<?php
		}

		}
	}
	
	?>
</span>

----------------------------------------------------------------


Regards,

Bob Patin
Longterm Solutions
bob at longtermsolutions.com
615-333-6858
http://www.longtermsolutions.com

   CONTACT US VIA SKYPE:
      USERNAME: longtermsolutions

   CONTACT US VIA INSTANT MESSAGING:
      AIM or iChat: longterm1954
      Yahoo: longterm_solutions
      MSN: bob at patin.com
      ICQ: 159333060





More information about the FX.php_List mailing list