I have taken bits and pieces of an upload script to upload files to my server, but it seems like every browser works fine except Safari. It's like a 50/50 chance that Safari will hang or upload it successfully. I'm dealing with 10-20mb files and so it's not fun to sit around for 5 minutes and then realize it wasn't working. I've tested with 200kb files so I know in a matter of seconds whether it worked or not. When it doesn't work and just is "loading" if I click upload again, it will work. I was wondering if maybe you could spot my problem in the code:
Here is the form:
That page takes a date passed to it via get and uses it to choose the location and filename for uploading.
Here is the actual uploader:
Unfortunately I can't allow access to this page for security reasons so you can't really test it. Just hoping you can see the problem . I removed a couple of file locations above...
Thanks.
Here is the form:
Code:
<html>
<title>File Upload</title>
<script type="text/javascript">
<!--
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
-->
</script>
</head>
<body>
<h2>File Upload</h2>
<?php
error_reporting(0);
$errors = array();
$mm = $_GET['mm'];
$dd = $_GET['dd'];
$yy = $_GET['yy'];
$date = $mm."/".$dd."/".$yy;
?>
<br /><p>Date: <?php echo $mm."/".$dd."/".$yy; ?><br /><br /><i>(The audio sermon must be an mp3 file under 20MB in size)</i></p>
<p><form enctype="multipart/form-data" action="audio_sermon_2a.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="21000000" />
<input type="hidden" name="year" value="<?php echo "20".$yy; ?>" />
<input type="hidden" name="mm" value="<?php echo $mm; ?>" />
<input type="hidden" name="dd" value="<?php echo $dd; ?>" />
<input type="hidden" name="yy" value="<?php echo $yy; ?>" />
Choose a sermon file to upload: <input type="file" name="file" size="30" /><br /><br /><br />
<div class="buttons"><button type="submit" name="submit" onclick="toggle_visibility('loadinggif');" class="positive"><img src="/images/icons/tick.png" alt="" /> Upload Sermon</button></div><br /><br /><br />
</form></p>
<div id="loadinggif" style="margin: 0; padding: 0; display: none;"><p><table border="0"><tr><td><img src="/images/loading.gif" alt="loading..." /></td><td valign="middle"> Uploading... please be patient...</td></tr></table></p></div>
</body>
</html>
Here is the actual uploader:
Code:
<?php
// ==============
// Configuration
// ==============
error_reporting(0);
$uploaddir = "path_to_location_hidden_just_because/".$_POST['year']; // Where you want the files to upload to - Important: Make sure this folders permissions is 0777!
$allowed_ext = "mp3"; // These are the allowed extensions of the files that are uploaded
$max_size = "21000000"; // 50000 is the same as 50kb
$max_height = ""; // This is in pixels - Leave this field empty if you don't want to
$max_width = ""; // This is in pixels - Leave this field empty if you don't want to upload images
// Check Entension
$extension = pathinfo($_FILES['file']['name']);
$extension = $extension['extension'];
$allowed_paths = explode(", ", $allowed_ext);
for($i = 0; $i < count($allowed_paths); $i++) {
if ($allowed_paths[$i] == "$extension") {
$ok = "1";
}
}
// Check File Size
if ($ok == "1") {
if($_FILES['file']['size'] > $max_size) {
print "<font color=\"red\">The sermon is too big! It can't be bigger than 20mb. Try making it smaller, <a href=\"#\" onclick=\"history.go(-1);return false;\">go back</a>, and upload it again.</font>";
exit;
}
// Check Height & Width
if ($max_width && $max_height) {
list($width, $height, $type, $w) = getimagesize($_FILES['file']['tmp_name']);
if($width > $max_width || $height > $max_height) {
print "File height and/or width are too big!";
exit;
}
}
// The Upload Part
if(is_uploaded_file($_FILES['file']['tmp_name'])) {
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_POST['mm'].".".$_POST['dd'].".".$_POST['yy'].".mp3");
print "<meta http-equiv=\"Refresh\" content=\"0; url=path_to_page_on_successful_upload?mm=".$_POST['mm']."&dd=".$_POST['dd']."&yy=".$_POST['yy']."\">";
}
} else {
print "<font color=\"red\">You must select a file to upload and it must be an mp3 file (ends in '.mp3'). Fix this, <a href=\"#\" onclick=\"history.go(-1);return false;\">go back</a>, and try uploading again.</font>";
}
?>
Unfortunately I can't allow access to this page for security reasons so you can't really test it. Just hoping you can see the problem . I removed a couple of file locations above...
Thanks.