Jump to content

file upload code


pouncer

Recommended Posts

i have this code firstly, but would lie to know what parts of it mean:

[code=php:0]
<html>
<head>
<title>A simple file upload form</title>
</head>
<body>
<form action="file_uploadTest.php" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="200000" />
<p><strong>File to upload:</strong> <input type="file" name="fileupload"></p>
<p><input type="submit" value="upload!"></p>
</form>
</body>
</html>
[/code]

<input type="hidden" name="MAX_FILE_SIZE" value="200000" />

200000 what?

and also what this means: enctype="multipart/form-data"

the actual php code to upload the file is

[code=php:0]
$file_dir = "dir..";

foreach($_FILES as $file_name => $file_array) {
echo "path: " . $file_array['tmp_name'] . "<br>\n";
echo "name: " . $file_array['name'] . "<br>\n";
echo "size: " . $file_array['type'] . "<br>\n";
echo "type: " . $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("Couldnt copy");

echo "file was moved<br><br>";
}
}
[/code]

is there an easier way to do this? im not sure what all the file array stuff is for and its hard to understand :s

hope someone can make it clear what it means thanks
Link to comment
https://forums.phpfreaks.com/topic/35256-file-upload-code/
Share on other sites

[quote]i have this code firstly, but would lie to know what parts of it mean:

<html>
<head>
<title>A simple file upload form</title>
</head>
<body>
<form action="file_uploadTest.php" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="200000" />
<p><strong>File to upload:</strong> <input type="file" name="fileupload"></p>
<p><input type="submit" value="upload!"></p>
</form>
</body>
</html>

<input type="hidden" name="MAX_FILE_SIZE" value="200000" />

200000 what?

and also what this means: enctype="multipart/form-data"

the actual php code to upload the file is



$file_dir = "dir..";






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





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





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





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





echo "type: " . $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("Couldnt copy");














echo "file was moved<br><br>";





}



}

is there an easier way to do this? im not sure what all the file array stuff is for and its hard to understand :s

hope someone can make it clear what it means thanks[/quote]

Hi,

200000 Bytes i.e. 2mb

Hope this helps
Link to comment
https://forums.phpfreaks.com/topic/35256-file-upload-code/#findComment-166582
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.