trying to upload videos via php

cybergolflesson

New Member
Can get images to upload and hoping to get help on how to upload videos instead. Don't really care if images upload but I really want to allow videos to upload. Hope you can help...here's my code

my html page...

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<table width="100%" border="0">
<tr>
<th bgcolor="#FF0000" scope="col"><span class="style47">UPLOAD - get help</span></th>
</tr>
</table>
<p class="style77">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
<span class="style54">Choose a swing to upload: </span>
<input name="uploadedfile" type="file" />
<br />
<input type="submit" value="Upload Swing" />
</p>
</form>

my php page...

<?PHP


// Where the file is going to be placed
$target_path = "uploadsvideo/";

/* Add the original filename to our target path.
Result is "uploadsvideo/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

echo "<pre>";
print_r($_FILES['media'])
echo "</pre>";

$target_path = "uploadsvideo/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded successfully";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
 

smoovo

New Member
You are missing semi-colon in your code (after print_r($_FILES['media'])), but that's one thing. Use this code instead of yours, i have made some changes and it's working.

PHP:
<?PHP

    $path = "uploadsvideo/";

    $target_path = $path . basename( $_FILES['uploadedfile']['name']);


    if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ". basename( $_FILES['uploadedfile']['name']) . " has been uploaded successfully";
    } else {
        echo "There was an error uploading the file, please try again!";
    }

?>

Also, you can get rid of the MAX_FILE_SIZE, your code not using it as a statement.
 

cybergolflesson

New Member
Thanks Smoovo

It does indeed work, and very condensed and efficient code you wrote, thanks very much. But only for files under 2mb it seems. Is there a line of code to up the file size accepted?
 

smoovo

New Member
I have told you to get rid of the MAX_FILE_SIZE in your form. To limit your uploaded file just add a new statement before your "if" statement. Each 1000 you are writing is just 1KB, that means if you want to limit to 100KB you will write 100000, and for 100MB it will be 100000000. Or, you can divide your file size by 1024 (real 1KB size) and check if it's equal to 100000.

PHP:
if (($_FILES['uploadedfile']['size']/1024)<=100000) { // equal to 100MB?
    if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ". basename( $_FILES['uploadedfile']['name']) . " has been uploaded successfully";
    } else {
        echo "There was an error uploading the file, please try again!";
    }
} else {
    echo "Your file is too large! Our limit is 100MB.";
}

That's it.
 
Top