File uploading - need help
Posted: Mon Nov 03, 2003 1:42 pm
Im creating a upload page for my site, but right now it doesn't work, the code looks like this:
But when i run it, i get the error saying "The file could not be copied to the server.".
Im running the script in the root (htdocs) on my apache server, and the folder the files should be uploaded to is named "Uploaded".
I think ive missed something here :/
Code: Select all
<div class="c2box">
<table class="txt" width="480" cellspacing="0" cellpadding="0">
<?php
if(!isset($upload)) {
$upload = "";
}
switch($upload) {
default:
include("source/uplcfg.php");
echo "
<tr><td class="tblheader"><font class="txtheader">Uploader</font></td></tr>
<tr><td>Maximum filesize is 500kb (0,5mb).<br>Filetypes allowed are: jpg, png, gif, bmp, psd, zip and txt.</td></tr>
<form ENCTYPE="multipart/form-data" method="post" action="index.php?id=uploader&upload=upload">
<input type="hidden" name="MAX_FILE_SIZE" value="500000">
<tr><td>Filename: <input type="file" name="file" SIZE="25"></td></tr>
<tr><td><input type="submit" value=" upload "></td></tr>
</form>
<tr><td><br><a href="index.php?id=uploader&op=view">View uploaded files</a></td></tr>
";
break;
case "upload":
include "source/uplcfg.php";
$result = "Uploaded file succesfully!<br>File location: <a href="$full_path/$file_name">$full_path/$file_name</a>";
if ($file_name == "") {
$result = "No file selected!";
}else{
if(file_exists("$upl_path/$file_name")) {
$result = "File does already exist, try renaming the file to upload.";
} else {
if (($size_limit == "yes") && ($limit_size < $file_size)) {
$result = "The file was to big, maximum filesize allowed is 500kb.";
} else {
$ext = strrchr($file_name,'.');
if (($limit_ext == "yes") && (!in_array($ext,$extensions))) {
$result = "The type of the file you are trying to upload isn't allowed.";
}else{
@copy($file, "$upl_path/$file_name") or $result = "The file could not be copied to the server."; // This is the error i get (PHP says that the file or directory doesn't exist)
}
}
}
}
echo "
<tr><td class="tblheader"><font class="txtheader">Uploader</font></td></tr>
<tr><td>$result</td></tr>
<tr><td><br><a href="index.php?id=uploader">Back</a><br><a href="index.php?id=uploader&op=view">View uploaded files</a></td></tr>
";
break;
}
?>
</table>
</div>Im running the script in the root (htdocs) on my apache server, and the folder the files should be uploaded to is named "Uploaded".
I think ive missed something here :/