PDA

View Full Version : Upload script stops working when file size too big.


tux
07-25-2009, 04:19 PM
Hello all,

I have an upload file script that works fine with file sizes that are quite small but fails without any errors if the file size is too big.

I cant figure out why!! The script works well and throws the errors that I have built in to it but I have tried to upload a file that is about 3Mb and the page just refreshes clearing the form fields, but throws no errors.

Can anyone shed some light on why this is happening.

Here is my code......

<?php

require_once("../Connection/PTPconnection.php"); // database connection
// uploaded_file is sent from the form on the previous page

//FILES UPLOADS
//Check that we have a file
if((!empty($_FILES["uploadedfile"])) && ($_FILES['uploadedfile']['error'] == 0)) {
//Check the file type and it's size.
$filename = basename($_FILES['uploadedfile']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "pdf" || $ext == "doc" || $ext == "wps") && ($_FILES["uploadedfile"]["size"] < 10000000)) {
//Determine the path to which we want to save this file
$target_path_file = "../PHP/downloads/".$_FILES['uploadedfile']['name'];
//Check if the file with the same name is already exists on the server
if (!file_exists($target_path_file)) {
//Attempt to move the uploaded file to it's new place
if ((move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$target_path_file))) {
$success = "Congratulations! Your file has been saved as: ".$filename;
} else {
$error = "That didn't work, File Error: A problem occurred during file upload. Please try again!!!";
}
} else {
$error = "That didn't work, File Error: The file you are trying to upload already exists. Please try again!!!";
}
} else {
$error = "That didn't work, File Error: Only .pdf, .doc or .wps files under 10Mb are accepted for upload. Please try again!!!";
}
} else {
$error = "";
}

echo $success;
echo $error;

$filesize = $_FILES["uploadedfile"]["size"]/1000;

if($filesize < 1000000){
$unit = "k";
}else $unit = "Mb";
///////////////////////////////////////////////////
$filetitle = $_POST['filetitle'];
$user = $_POST['user'];


if($success){
$query = sprintf("INSERT INTO docs (filename, filetitle, filesize, user)
values ('$filename', '$filetitle', '$filesize', '$user')");
mysql_query($query)or die(mysql_error());
}
///////////////////////////////////////////////////
$query = sprintf("SELECT * FROM docs");
$result = @mysql_query($query);
$docs = @mysql_fetch_array($result);

?>

<form enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
<fieldset>
<legend>New Image Details</legend>
<ol>
<li>
<label for="filetitle">File Title<em>*</em></label>
<input name="filetitle" id="filetitle" type="input" class="form"/>
</li>
<p></p>
<li>
<label for="uploadedfile">New File<em>*</em></label>
<input name="uploadedfile" id="uploadedfile" type="file" value="Browse" class="form"/>
</li>
<p></p>
<li>
<label for="user">Uploaded by?<em>*</em></label>
<input name="user" id="user" type="input" class="form"/>
</li>
<p></p>
<li>
<input type="submit" value="Upload New Image" class="form" />
</li>
<p></p>

</ol>
</fieldset>
</form>

<div><h5>Links to documents:</h5>
<?php do { ?>
<a href="http://localhost/PaulTuckerPhotography/PHP/downloads/<?php echo $docs['filename']; ?>"><?php echo $docs['filetitle']; ?></a> <?php echo $docs['filesize']; ?><?php echo $unit; ?><br>
<?php } while($docs = mysql_fetch_array($result)) ?>
</div>

Many thanks, regards Paul

edbr
07-26-2009, 03:25 AM
did you check what limit your server has?

m1a2x3x7
07-28-2009, 05:59 PM
Check your php.ini file it will have a size limit set.