Evening Folks,
I was wondering if anyone could shed some light on what i may be doing wrong here.
I have been trying to learn how to upload files to a directory on a web server. My main objective is to allow someone to upload a file to a directory on my webspace i.e. http://www.mysite.com/files
I am aware that the directory required to store the user uploaded images needs 0777 file permission which I have already set.
Also I read somewhere that running php in safe mode could cause problems, so i verified that my web host was not running php in safe mode.
So... As far as i can see I should be able to use the following script, (which is from Sam's teach yourself php), to upload a file from within a browser. Its copied exact for the moment in hope that it would work
<html>
<head>
<title>Listing 9.13 A simple file upload form</title>
</head>
<body>
<form action="listing9.14.php" enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="51200">
<p><strong>File to Upload:</strong> <input type="file" name="fileupload"></p>
<p><input type="submit" value="upload!"></p>
</form>
</body>
</html>
<html>
<head>
<title>Listing 9.14 A file upload script</title>
</head>
<body>
<h1>File Upload Results</h1>
<?php
$file_dir = "http://www.mysite.co.uk/files";
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>";
}
}
?>
</body>
</html>
But after clicking submit, i get a page echoing the $file array
and a message saying couldnt copy.
I dont understand whats going on. I'd really appreciate any help.
Thanks for reading
chinrub