hi friends, i am not getting why am i getting this error when i try to upload files.. as all files are getting upload but may be larger files arent..but code shows some other problem than size.. i tried less than 2 mb, it got uploaded but higher than 2mb not getting upload.. really not understanding it. as filesize limit is also allot higher than 2 mb. help me .
and also, can somebody add url upload feature to this script? hmm, i will also try to do with new sql row.
please solve error for me as i liked this uploader for my site. thank you in advance!!
PHP Code:
$time = date("d.m.Y, H:i:s");
$Browser = $_SERVER[HTTP_USER_AGENT];
$ip=$_SERVER[REMOTE_ADDR];
$desc=trim($_POST['desc']);
$user=trim($_POST['user']);
if(!$desc) $desc="No description available.";
if(!$user) $user="Guest";
// apare input-ul atata timp cat nu e Opera MIni 3.
if (preg_match("/Opera Mini/i", $Browser) && !preg_match("/Opera Mini\/3.0/i", $Browser)) $OperaMini = TRUE;
$no="no";
header("Cache-Control: no-cache, must-revalidate");
header("Content-type: text/html; charset=ISO-8859-1");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
echo "<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\"
\"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">\n";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
echo "<head>\n";
include("config.php");
echo "<title>Upload File</title>";
echo "<link rel='stylesheet' href='style.css' type='text/css'/>";
echo "</head>\n";
echo "<body>";
echo "<table bgcolor=\"#B0DBED\" width=\"100%\">";
echo "<tr><td><font color='green' size='5'>Mobile</font><font color='blue' size='5'>Share</font></td></tr></table>";
echo "<div class='hl'>Upload file</div>";
if($_GET[page] !=="add"){
echo "<form method=\"post\" enctype=\"multipart/form-data\" action=\"upload.php?page=add\">";
if ($OperaMini) {
echo "<input type='text' name='file1' size='30'/> <a href='op:fileselect'>Browse files</a><br>";
}
else {
echo "<input type=\"file\" name=\"filetoupload\"><br>";
}
echo "<input type=\"Submit\" name=\"uploadform\" value=\"Upload File\">";
echo "(max. <b>".$mb."</b> MB)</div>";
echo "<div class=\"hl\">Optional</div>";
echo "<div class=\"txt\"><b><font color=\"green\">User:</font></b>";
echo "<br/><input type=\"text\" value=\"".$COOKIE["WapShareUser"]."\" name=\"user\" size=\"30\" /><br/>";
echo "<div class=\"txt\"><b><font color=\"green\">Description:</font></b>";
echo "<br/><textarea name=\"desc\" rows=\"4\" cols=\"40\"></textarea><br/>";
echo "<small>Notice: once you submit the file, it will be available to public.</small>";
echo "<br/><b>Please wait while the file is uploaded, it may take several minutes depending by the size of the file and by your internet bandwidth.</b>";
echo "</div>";
echo "</form>";
}
if ($_REQUEST[file1]) {
$file1 = $_REQUEST[file1];
$file1 = explode("=", $file1);
$file_content = $file1[1];
$filename = str_replace("file", "", $file1[0]);
$size = strlen($file_content);
}
else {
$filename = $_FILES['filetoupload']['name'];
$size = $_FILES['filetoupload']['size'];
}
$ext = strrchr($filename,'.');
$truext=str_replace(".","",$ext);
$truext=strtolower($truext);
$ext=strtolower($ext);
$upload_dir=htmlspecialchars("$truext/");
$filename=str_replace(" ","_",$filename);
$filename=str_replace("`","",$filename);
$filename=str_replace("]","",$filename);
$filename=str_replace("[","",$filename);
$filename=str_replace("~","",$filename);
$filename=str_replace("@","",$filename);
$filename=str_replace("#","",$filename);
$filename=str_replace("%","",$filename);
$filename=str_replace("^","",$filename);
$filename=str_replace("*","",$filename);
$filename=str_replace("|","",$filename);
$filename=str_replace("$","",$filename);
$filename=str_replace("<","",$filename);
$filename=str_replace("<","",$filename);
$filename=str_replace(">","",$filename);
$filename=str_replace(">","",$filename);
$filename=str_replace("\"","",$filename);
$filename=str_replace("'","",$filename);
$filename=str_replace("\\","",$filename);
if($_GET['page']=="add"){
if (!$filename)
{
echo "<b>Please select a file for upload.</b><br />";
echo "<br /><div class='hl2'>";
echo "<a href=\"upload.php\"><b>[Upload] </b></a>";
echo "<a href=\"index.php\"><b>[Menu]</b></a>";
echo "<div><br />";
echo "<table bgcolor=\"B0DBED\" width=\"100%\"><tr><td>Powered by <a href=\"$homepage_url\">$admin</a></td></tr></table>";
die();
}// i am getting this condition error. (please select a file for upload, but i already selected file). and if i remove this condition then getting error downwards..
if (($extlimit == "yes") && (in_array($ext,$limitedext)))
{
echo("Extension <b>$ext</b> was disabled due security reasons.The file was NOT uploaded!<br />");
echo "<br />";
echo "<br /><div class='hl2'>";
echo "<a href=\"upload.php\"><b>[Upload] </b></a>";
echo "<a href=\"index.php\"><b>[Menu]</b></a>";
echo "<div><br />";
echo "<table bgcolor=\"B0DBED\" width=\"100%\"><tr><td>Powered by <a href=\"$homepage_url\">$admin</a></td></tr></table>";
die();
}
if(strlen($filename)>$lungime_nume)
{
echo "<b><font color=\"red\">Your file name has a name too long.Please rename it!</font></b><br />";
echo "<br /><div class='hl2'>";
echo "<a href=\"upload.php\"><b>[Upload] </b></a>";
echo "<a href=\"index.php\"><b>[Menu]</b></a>";
echo "<div><br />";
echo "<table bgcolor=\"B0DBED\" width=\"100%\"><tr><td>Powered by <a href=\"$homepage_url\">$admin</a></td></tr></table>";
die();
}
if ($size > $size_bytes)
{
echo "<b><font color=\"red\">Your file size is too big.Maximum allowed is $mb MB.</font></b><br />";
echo "<br /><div class='hl2'>";
echo "<a href=\"upload.php\"><b>[Upload] </b></a>";
echo "<a href=\"index.php\"><b>[Menu]</b></a>";
echo "<div><br />";
echo "<table bgcolor=\"B0DBED\" width=\"100%\"><tr><td>Powered by <a href=\"$homepage_url\">$admin</a></td></tr></table>";
die();
}
if (file_exists("$upload_dir/$filename"))
{
echo("<b><font color=\"red\">File already exist.Please rename your file!</font></b><br />");
echo "<br /><div class='hl2'>";
echo "<a href=\"upload.php\"><b>[Upload] </b></a>";
echo "<a href=\"index.php\"><b>[Menu]</b></a>";
echo "<div><br />";
echo "<table bgcolor=\"B0DBED\" width=\"100%\"><tr><td>Powered by <a href=\"$homepage_url\">$admin</a></td></tr></table>";
die();
}
if ($file1) {
if(!is_dir($upload_dir)){mkdir($upload_dir); chmod($upload_dir,0777); copy("htaccess.txt","$upload_dir.htaccess");}
$fp = fopen($upload_dir.$filename, "w") or die("File cannot be saved due server permissions");
fwrite($fp, base64_decode($file_content));
if (fclose($fp)) $Uploaded = TRUE;
}
else {
if(!is_dir($upload_dir)){mkdir($upload_dir); chmod($upload_dir,0777); copy("htaccess.txt","$upload_dir.htaccess");}
move_uploaded_file($_FILES['filetoupload']['tmp_name'], $upload_dir.$filename) or die("Cannot move uploaded file");// if remove upper condition than getting this die error. help me ..
$Uploaded = TRUE;
}
if ($Uploaded)
{
mysql_query("INSERT INTO mobileshare (banned,file,user,browse,ip,ftype,uploaded,description,size) VALUES ('$no','$filename','$user','$Browser','$ip','$truext','$time','$desc','$size')");
$sql = mysql_query("SELECT * FROM mobileshare WHERE file = '$filename' ");
while($row = mysql_fetch_array($sql)){
$id = $row['id'];}
echo ("<b><font color=\"red\">Your file was uploaded </font><a href=\"file.php?id=$id\">here</a></b><br />
<u>Copy and paste the following code:</u><br />
<textarea name=\"link\" rows=\"5\" cols=\"40\">".$url."/file.php?id=".$id."</textarea><br />");
echo "<br /><div class='hl2'>";
echo "<a href=\"upload.php\"><b>[Upload] </b></a>";
echo "<a href=\"index.php\"><b>[Menu]</b></a>";
echo "<div><br />";
echo "<table bgcolor=\"B0DBED\" width=\"100%\"><tr><td>Powered by <a href=\"$homepage_url\">$admin</a></td></tr></table>";
die();
}
else
{
echo "<b><font color=\"red\">Unexpected error.Please try again.</font></b><br />";
echo "<br />";
echo "<br /><div class='hl2'>";
echo "<a href=\"upload.php\"><b>[Upload] </b></a>";
echo "<a href=\"index.php\"><b>[Menu]</b></a>";
echo "<div><br />";
echo "<table bgcolor=\"B0DBED\" width=\"100%\"><tr><td>Powered by <a href=\"$homepage_url\">$admin</a></td></tr></table>";
die();
}
}
echo "<br /><div class='hl2'>";
echo "<a href=\"upload.php\"><b>[Upload] </b></a>";
echo "<a href=\"index.php\"><b>[Menu]</b></a>";
echo "<div><br />";
echo "<table bgcolor=\"B0DBED\" width=\"100%\"><tr><td>Powered by <a href=\"$homepage_url\">$admin</a></td></tr></table>";
echo "</body>";
echo "</html>";
please solve error for me as i liked this uploader for my site. thank you in advance!!
Comment