Jump to content

File Upload Problem


hanlonj

Recommended Posts

Hi,

 

The following code is supposed to upload a file to a directory on my local testing server called "upload_directory". It get's it's info from a simple file upload form. It echoes to the screen that "File was moved!" but when I check if it has been moved, it hasn't. Any ideas?

 

<?php

$file_dir = "..\upload_directory";

foreach ($_FILES as $file_name => $file_array){

echo "path: ".$file_array['tmp_name']. "<br>\n";
echo "name: ".$file_array['name']. "<br>\n";
echo "type: ".$file_array['type']. "<br>\n";
echo "size: ".$file_array['size']. "<br>\n";

if (is_uploaded_file($file_array['tmp_name'])){
	move_uploaded_file($file_array['tmp_name'],
		"\$file_dir\$file_array['name']") or die ("Couldn't Copy!");

	echo "File was moved!<br><br>";

	}
}

?>


Link to comment
https://forums.phpfreaks.com/topic/57973-file-upload-problem/
Share on other sites

  Quote

Have you checked the permissions on 'upload_directory'?

 

Yes, it's just on my local machine at the moment so I presume the windows default setting for folders will suit? Just to be sure I have opened it up for sharing and it still doesn't work.Is there any obvious bug in the code?

 

stoney

Link to comment
https://forums.phpfreaks.com/topic/57973-file-upload-problem/#findComment-288333
Share on other sites

Hi,

 

Try this.....

 

$file_dir = "../upload_directory/";

foreach ($_FILES as $file_name => $file_array)

{

echo "path: ".$file_array['tmp_name']. "<br>\n";

echo "name: ".$file_array['name']. "<br>\n";

echo "type: ".$file_array['type']. "<br>\n";

echo "size: ".$file_array['size']. "<br>\n";

if (is_uploaded_file($file_array['tmp_name']))

{

move_uploaded_file($file_array['tmp_name'], $file_dir . $file_array['name']) or die ("Couldn't Copy!");

echo "File was moved!<br><br>";

}

}

 

;)

Link to comment
https://forums.phpfreaks.com/topic/57973-file-upload-problem/#findComment-288594
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.