 Below is the script i wrote to upload my files to my webserver download director. it does work for smaller files but when a file of about 50mb is to be upload it does not work and shows blank page. the error messages i set to show in case of the script failure also does not show. i set the value of the post_max_size in php.ini file to 100M but to no avail.please help.
Code:
<form action="../cms/add.php" method="post" name="form3" id="form3" enctype="multipart/form-data">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Description:</td>
<td><input type="text" name="description" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right" valign="top">location:</td>
<td><input type="file" name="filepath" size="32"/>
</td>
</tr>
<tr valign="baseline">
<td align="center" colspan="2"><input type="submit" value="ADD" /></td>
</tr>
</table>
</form>
PHP Code:
<?php require_once('Connections/sql1.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } function calc($size) { $kb=1024; $mb=1048576; $gb=1073741824; $tb=1099511627776; if(!$size) return '0 B'; elseif($size<$kb) return $size.' B'; elseif($size<$mb) return (round($size/$kb, 2).' KB'); elseif($size<$gb) return (round($size/$mb, 2).' MB'); elseif($size<$tb) return (round($size/$gb, 2).' GB'); else return (round($size/$tb, 2).' TB'); } if ($_FILES){ error_reporting(E_ALL ^ E_NOTICE); // Doublecheck that we really had a file: if(!$_FILES['filepath']['size']) { echo "No actual was uploaded"; exit(); } else { // Determine the filename to which we want to save this file: $newname = "..\\downloads\\".basename($_FILES['filepath']['name']); $filepath= "downloads/".basename($_FILES['filepath']['name']); $filetype=$_FILES['filepath']['type']; $filesize=$_FILES['filepath']['size']; $filesize= calc($filesize); // Attempt to move the uploaded file to it's new home: /* if (!(move_uploaded_file($_FILES['filepath']['tmp_name'], $newname))) { echo "<p>ERROR: A problem occurred during file upload!</p>\n"; exit(); } else {*/ // It worked! $_POST['filepath']=$filepath; if(!get_magic_quotes_gpc()) { $_POST['filepath']=addslashes($filepath); } $insertSQL = sprintf("INSERT INTO downloads (description,type,size,url) VALUES (%s, %s,%s,%s)", GetSQLValueString($_POST['description'], "text"), GetSQLValueString($filetype, "text"), GetSQLValueString($filesize, "text"), GetSQLValueString($_POST['filepath'], "text")); mysql_select_db($database_sql1, $sql1); $Result1 = mysql_query($insertSQL, $sql1) or die(mysql_error());
echo "<p>Done! The file has been saved as: {$newname}</p>\n"; // } } }
|