I have some trouble uploading large FLV files via a form. Here is my code:
Code: Select all
<form action="edit_showreel.php?actor=<?php echo $sel_actor['id'];?>¤tpage=<?php echo $currentpage;?>" method="post" enctype="multipart/form-data">
<label for="uploadedfile">Filename:</label>
<input type="file" name="uploadedfile" id="uploadedfile" />
<input type="submit" name="submit1" value="Submit" />
</form>
<?php
if (isset($_POST['submit1'])) {
echo "<br/>Please wait while we attempt to upload your file...<br><br>";
$target_path = "files/showreel/";
$flag = 0; // Safety net, if this gets to 1 at any point in the process, we don't upload.
$filename = $_FILES['uploadedfile']['name'];
$filesize = $_FILES['uploadedfile']['size'];
$mimetype = $_FILES['uploadedfile']['type'];
$filesize2 = substr($_FILES['uploadedfile']['size'] / 1000000, 0, 4);
$filename = htmlentities($filename);
$filesize = htmlentities($filesize);
$mimetype = htmlentities($mimetype);
$target_path = $target_path . basename( $filename );
if ($filename != "") {
echo "Beginning upload process for file named: ".$filename."<br>";
echo "Filesize: ".$filesize2." Mo<br>";
echo "Type: ".$mimetype."<br><br>";
}
//First generate a MD5 hash of what the new file name will be
//Force a FLV extention on the file we are uploading
$hashedfilename = md5($filename);
$hashedfilename = $hashedfilename.".flv";
//Check for empty file
if ($filename == "") {
$error = "No File Exists!";
$flag = $flag + 1;
}
//Whitelisted files - Only allow files with FLV extention onto server...
$whitelist = array(".flv");
foreach ($whitelist as $ending) {
if(substr($filename, -(strlen($ending))) != $ending) {
$error = "The file type or extention you are trying to upload is not allowed! You can only upload MP3 files to the server!";
$flag++;
}
}
if ($filesize > 25000000) {
//File is too large
if($flag == 0){
$error = "The file you are trying to upload is too large! Your file can be up to 25 MB in size only. Please upload a smaller FLV file or encode your file with a lower bitrate.";
}
$flag = $flag + 1;
}
if ($filesize < 5000000) {
//File is too small
if($flag == 0){
$error = "The file you are trying to upload is too small! Your file has been marked as suspicious because our system has determined that it is too small to be a valid FLV file. Valid FLV files must be bigger than 5 MB and smaller than 25 MB.";
}
$flag = $flag + 1;
}
//Check the mimetype of the file
if ($mimetype != 'video/x-flv') {
if($flag == 0){
$error = "The file you are trying to upload does not contain expected data. Are you sure that the file is a FLV?";
}
$flag = $flag + 1;
}
//All checks are done, actually move the file...
if ($flag == 0) {
//Now we check that the file doesn't already exist.
$existname = "files/showreel/".$hashedfilename;
if (file_exists($existname)) {
unlink($existname);
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);
rename("files/showreel/".$filename, "files/showreel/".$hashedfilename);
echo "The file ". basename( $filename ). " has been uploaded. You can <a href=\"edit_actor_media.php?actor=$sel_actor[id]¤tpage=$currentpage\">go back to his profile</a><br/>";
$id = mysql_prep($_GET['actor']);
$query = "UPDATE actors SET
show_reel = '{$hashedfilename}'
WHERE id = {$id}";
$result = mysql_query($query, $connection);
} else {
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
//Change the filename to MD5 hash and FORCE a FLV extention.
if (@file_exists("files/showreel/".$filename)) {
//Rename the file to an MD5 version
rename("files/showreel/".$filename, "files/showreel/".$hashedfilename);
echo "The file ". basename( $filename ). " has been uploaded. You can <a href=\"edit_actor_media.php?actor=$sel_actor[id]¤tpage=$currentpage\">go back to his profile</a><br/>";
$id = mysql_prep($_GET['actor']);
$query = "UPDATE actors SET
show_reel = '{$hashedfilename}'
WHERE id = {$id}";
$result = mysql_query($query, $connection);
} else {
echo "There was an error uploading the file, please try again!";
}
} else {
echo "There was an error uploading the file, please try again!";
}
}
} else {
echo "File Upload Failed!<br>";
if ($error != "") {
echo $error;
}
}
}
?>
What it does is that it seems to refresh itself when I click on Submit. No error message or anything happens... I used this script for pdf and mp3 files and it worked well...
Any idea what went wrong?