# PHP move\_uploaded\_file won’t play nice

**URL:** <https://boards.straightdope.com/t/php-move_uploaded_file-won-t-play-nice/466367>\
**Category:** Factual Questions\
**Created:** [October 3, 2008, 8:32pm UTC](https://boards.straightdope.com/t/php-move_uploaded_file-won-t-play-nice/466367 "2008-10-03T20:32:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rhythmdvl](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@Rhythmdvl](https://boards.straightdope.com/u/Rhythmdvl)\
**Post date:** [October 3, 2008, 8:32pm UTC](https://boards.straightdope.com/t/php-move_uploaded_file-won-t-play-nice/466367/1 "2008-10-03T20:32:06Z")

</div>

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

```auto

<!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>

```

---

<div class="post-metadata">

**Author:** ![lexi](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lexi/32/6806_2.png) [@lexi](https://boards.straightdope.com/u/lexi)\
**Post date:** [October 3, 2008, 10:10pm UTC](https://boards.straightdope.com/t/php-move_uploaded_file-won-t-play-nice/466367/2 "2008-10-03T22:10:40Z")

</div>

…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](http://drupal.org/node/97193)

---

<div class="post-metadata">

**Author:** ![Rhythmdvl](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@Rhythmdvl](https://boards.straightdope.com/u/Rhythmdvl)\
**Post date:** [October 3, 2008, 10:54pm UTC](https://boards.straightdope.com/t/php-move_uploaded_file-won-t-play-nice/466367/3 "2008-10-03T22:54:24Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Crowbar\_of\_Irony\_3](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@Crowbar\_of\_Irony\_3](https://boards.straightdope.com/u/Crowbar_of_Irony_3)\
**Post date:** [October 4, 2008, 7:20am UTC](https://boards.straightdope.com/t/php-move_uploaded_file-won-t-play-nice/466367/4 "2008-10-04T07:20:39Z")

</div>

> [@Rhythmdvl](#):
>
> 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.

> **[W3Schools.com](http://www.w3schools.com/PHP/php_ref_ftp.asp)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

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