PHP move_uploaded_file won’t play nice

I just don’t get it. I’m trying to set up a simple file sharing space on our Web page, so clients can send and receive files that are too large to email (150 — 200 MB Quark and image files).

So I poked around and futzed about and came up with a page that allows me to up- and download files. Except. Except I’ve been using PDFs and other small files to test it with. As soon as I tried with a slightly larger file (just 7MB), the page hung up. Sometimes the submit button does nothing, sometimes it looks like it’s reloading but never ends. I’m assuming that either I’m using the wrong command to do this with, or there is some endless loop in my code.

I’ve also tried it on a couple platforms. I started on a Linux box here I use to test. Since it’s on our LAN, transfer speed (especially with a 7 MB file) wasn’t an issue. Also, just to be sure I put the page on our Host’s site to see if anything changed. Nada.

FWIW, It will be in a (strong) password-protected directory, and only clients will have access to the directory (passwords will be changed after the need is over). Given the limited access and level of trust, I don’t need to implement any security measures (e.g., file type restrictions, stripping). Oh, and given the sensitivity of the client, Yousendit and other third-party sites are not an option.

Is there any chance someone could let me know if move_uploaded_file is the wrong command for this? Or is there a glaring error somewhere in here that I’m oblivious to?

Thanks,

Rhythm



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php 
function getFileList($dir) 
 { # array to hold return value 
 $retval = array(); 
 
 # add trailing slash if missing 
 if(substr($dir, -1) != "/") $dir .= "/"; 
 
 # open pointer to directory and read list of files 
 $d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading"); 
 while(false !== ($entry = $d->read())) { 
 
 	# skip hidden files 
	if($entry[0] == ".") continue; 
	if(is_dir("$dir$entry")) { 
	$retval[] = array( 
		"name" => "$dir$entry/", 
		"type" => filetype("$dir$entry"), 
		"size" => 0,
		"lastmod" => filemtime("$dir$entry") 
		); 
				 sort($retval);

	} elseif(is_readable("$dir$entry")) {
		 $retval[] = array( 
		 "name" => "$entry", 
		 "type" => mime_content_type("$dir$entry"),
		 "size" => filesize("$dir$entry"),
		 "lastmod" => filemtime("$dir$entry") 
		 ); 
		 sort($retval);
		 }
		  }
		   $d->close(); 
		   return $retval; 
		   }
		   
//call the listing function 
$dirlist = getFileList("documents/");

	
		  
// Upload file code
// $target is where the files should go -- relative to this page's location
$target = "documents/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
//Check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file wasn't uploaded (L. 35)";
}

//Upload if everything is OK
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo '<meta http-equiv="REFRESH" content="0;url=./thanks.php">';
 
}

} 
?>		  

</head>

<body>
<?php 
echo "<table>
"; 
echo "<tr><th>Name</th><th>~Size (MB)</th></tr>
"; 

	foreach($dirlist as $file) { 
	echo "<tr>
"; 
	//echo "<td>{$file['name']}</td>
";
	echo ("<td><a href='documents/{$file['name']}'>{$file['name']}</a></td>
" );
	//echo "<td>{$file['type']}</td>
"; 
	//echo "<td>{$file['size']}</td>
"; 
		$f_size = $file['size'];
		$round_f_size = round($f_size/pow(1024, 2), 2);
		echo "<td> $round_f_size <td>
";
	echo "<td>" . date("r", $file['lastmod']) . "</td>
"; 
	echo "</tr>
"; 
	} 
	echo "</table>

";
	
	    
?>
<p> </p>
<form enctype="multipart/form-data" action="index.php" method="POST">
  <div align="left">Please select a file to upload:
    <input name="uploaded" type="file" size="100" />  
    <br />
    <input name="submit" type="submit" value="Upload" />
  </div>
</form>

</body>
</html>



…never mind what I said before…

It may be part of the php.ini - there is a setting in there for the maximum upload file’s size.

Check this link:
http://drupal.org/node/97193

Thanks for your input – that was exactly it.

Yikes.

I just got off the phone with our hosting company. They have an un-editable limit set at 2MB:eek:

They do have a large enough window via straight FTP, but that’s not really something I want to give out to clients (getting them to use an FTP program is problematic, plus the shared hosting package generates a slightly unprofessional login name).

Can a PHP script use FTP credentials to shuffle things around?

That’s probably a question for a separate thread…

Yes, you could - I have done a FTP variant of move_upload_file before when the private server refuses to turn off the ultra-strict safety mode.

This link has the FTP functions reference.

PS: You may want to reconsider a new web-host…