I found this tuturial that looks like a pretty easy example. When I try to upload something it gives me this error:
Warning: copy(files/test.gif): failed to open stream: Permission denied in /home/trackiec/public_html/upload.php on line 17
Does this mean I have to set permissions somewhere on my server?
Here is the code to my page
<HTML>
<HEAD>
</HEAD>
<BODY>
<form name="form1" method="post" action="" enctype="multipart/form-data">
<input type="file" name="imagefile">
<input type="submit" name="Submit" value="Submit">
Here we just did a form, a filebutton and a submit button.
Now for the fun part:
<?
if(isset( $Submit ))
{
//If the Submitbutton was pressed do:
if ($FILES['imagefile']['type'] == "image/gif"){
//Check if the image type from the selected file is gif. If the type is gif then we want to copy it like this:
copy ($FILES['imagefile']['tmp_name'], "files/".$FILES['imagefile']['name'])
or die ("Could not copy");
//Copy the temporary file with 'tmp_file' to the our desired location. A temp file usually look like "C:\PHP\uploadtemp\php42F.tmp" and we both know that that's not the file we selected, copy it in using only 'name' to get it right. Thats it really, your file is uploaded but lets write some info about the file we just uploaded to the browser.
echo "";
echo "Name: ".$FILES['imagefile']['name']."";
echo "Size: ".$FILES['imagefile']['size']."";
echo "Type: ".$FILES['imagefile']['type']."";
echo "Copy Done....";
}
//The browser should now display the name, size and type of file uploaded, type should be image/gif because thats the only type we are allowing to be uploaded
else {
echo "";
echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")";
}
}
//Else, The file is not an gif, write out an errormessage and display the name of the file the user tried to upload. Close the form and you are all done.
?>
</form>
</BODY>
</HTML>