PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<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>
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 :/
Is the "uploaded/" folder already created? PHP cannot upload to a folder that doesn't exist. I forget that all the time and spend hours trying to figure out what I did wrong. Also, to get the "uploaded/" folder from the root you need to do something like:
DuFF wrote:Is the "uploaded/" folder already created? PHP cannot upload to a folder that doesn't exist. I forget that all the time and spend hours trying to figure out what I did wrong. Also, to get the "uploaded/" folder from the root you need to do something like:
Ok, edited the whole site, and then i figured out what was the problem, when i included the file in my index.php it wouldn't work, but when i ran the page itselft, it worked perfectly. Something on my index.php makes the code not to work.