Uploading video files in the mysql database - mysql

This code can upload video files but only to my specific folder. How can I upload the video files into my database and retrieve it for viewing/streaming. Could you help me please? I have read something about just not uploading it to the database but uploading it to the server? What does that means?
This is my view:
<body>
<div id="container">
<h1>Welcome</h1>
<div id="body">
<div id="div2">
<div id="upload">
<form class="cssform" name="property" id="property" method="POST" action="<?php echo base_url()?>main/add_video" enctype="multipart/form-data" >
<table>
<tr>
<td><input type="file" id="video" name="video" ></td>
</tr>
<tr>
<td> <input type="submit" id="button" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
</div>
<a href='<?php echo base_url()."main/logout" ?>'>Logout</a>
</div>
<div id ="searchBox">
</div>
</div>
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>
</body>
This is my controller:
public function add_video(){
if (isset($_FILES['video']['name']) && $_FILES['video']['name'] != '') {
unset($config);
$date = date("ymd");
$configVideo['upload_path'] = './videos';
$configVideo['max_size'] = '10240';
$configVideo['allowed_types'] = 'avi|flv|wmv|mp3';
$configVideo['overwrite'] = FALSE;
$configVideo['remove_spaces'] = TRUE;
$video_name = $date.$_FILES['video']['name'];
$configVideo['file_name'] = $video_name;
$this->load->library('upload', $configVideo);
$this->upload->initialize($configVideo);
if (!$this->upload->do_upload('video')) {
echo $this->upload->display_errors();
} else {
$videoDetails = $this->upload->data();
echo "Successfully Uploaded";
}
}
}

You do NOT want to upload to the database...that would become an enormous amount of data to be unnecessarily managed by MySQL, not to mention a huge development undertaking to view the videos.
You could change your code to determine what folder it should be uploaded to, and move it there after the upload to .videos\ is complete. Perhaps by username, or date or similar, and have a table in your database that stores the folder name of where the file is located and other video related information.
At that point, you can use MySQL to locate the files, and other info you've stored, and use that to create a valid link to view the video, which would be in the folder that it was moved to.

Related

html forms download file django

I am stuck with this issue in Django: I want to download a file already existing on my server through a html form. The file to be downloaded is served through a function in views. My problem is with html form and passing the file name to view. How can I pass the name of the file from form toward view without having to select the file?
In html I have:
# 'content' keeps the name of the file to be downloaded
{% block content %}
{{content}}
<table>
<tr>
<td>
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="file"/>
<br />
<input type="submit" value="Download File" />
</form>
</td>
</tr>
</table>
{% endblock %}
When I select the file and press submit button, it works but I need a different behavior: the name of the file containing results (downloadable file) to be passed to views into a variable. The views will then serve it.
The view which handled the downloadable file:
def forecast(request):
if request.method == 'POST':
#handle_download_file(request.FILES['file'], str(request.FILES['file']))
print('request.method este: ',request.method)
RESULTS_filename = 'frcst_'+ str(request.FILES['file'])
#download('GET', RESULTS_filename)
file_path = os.path.join(os.path.relpath('forecast/'), RESULTS_filename)
print (file_path)
print(settings.MEDIA_ROOT)
with open(file_path,'rb') as fh:
response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel")
response['content-disposition'] = 'attachment; filename='+RESULTS_filename
print(response)
return response
HttpResponseRedirect('/forecast/')
return render(request,'result_links.html',{'content':'frcst_history.csv'})

Why won't my comment system work? [HTML]

I am a beginner in html, and I am beginning to develop my first website. I watched a video to learn to code a commentary system, here is the link:
https://www.youtube.com/watch?v=O4BkHj7Ws9U
My page does resemble what is shown in the video, but there is some errors, take a look at my webpage after watching the video, as you can see, there are errors:
Here is my code:
<HTML>
<form action="" method="post">
<label> Name: <br><input type="text" name="name"><br></label>
<label> Message: <br><textarea cols="35" rows="5" name="mes"></textarea></label><br>
<input type="submit" name="post" value="Post">
</form>
</HTML>
<?php
$name = $_POST["name"];
$text = $_POST["mes"];
$post = $_POST["post"];
if ($post){
#WRITE DOWN COMMENTS#
$write = fopen("com.txt", "a+");
fwrite($write, "<u><b> $name</b></u><br>$text<br></br>");
fclose($write);
#DISPLAY COMMENTS#
$read = fopen("com.txt", "r+t");
echo "All comments:";
while(!feof($read)){
echo fread($read, 1024);
}
fclose($read);
}
else{
#DISPLAY COMMENTS#
$read = fopen("com.txt", "r+t");
echo "All comments:<br>";
while(!feof($read)){
echo fread($read, 1024);
}
fclose($read);
}
?>
Thank you for your help, sorry, I'm sort of a newbie at this.
You should use something like MAMP to run php code.
Or upload everything to a webserver.
You have to save your file as a PHP file.

Uploading images to database in codeigniter?

I tried searching but no success i want to upload max 5 images to database along with user form data.I have table where all user data of form posted is saved along with images uploaded[image upload is attached with user form] picture fields in database are named as pic1,pic2,pic3.. pic5 + email,password etc I am successfull in uploading image data to database but not images.
//controller
if ($this->form_validation->run()!=true) {
$data['countryDrop'] = $this->Country_states_cities->getCountries();
$this->load->view('header');
$this->load->view('register',$data); //Display page
$this->load->view('footer');
}else{
$form=array();
$form['first_name']=$this->input->post("first_name",true);
$form['last_name']=$this->input->post("last_name",true);
$form['dob']=date('Y-m-d',strtotime($this->input->post("dob",true)));
$form['email']=$this->input->post("email",true);
$form['password']=sha1($this->input->post("password",true));
$form['phone']=$this->input->post("phone",true);
$form['addline2']=$this->input->post("addressline2",true);
$form['zip']=$this->input->post("zip",true);
$result = $this->Couch_reg->insert_new_user($form); //call to model
//model
function insert_new_user($form)
{
$this->db->insert('tbl_usrs',$form);
if ($this->db->affected_rows() > 0) {
return true;
} else {
return false;
}
}
//view
<input type="file" name="uploadfile[]" accept = "image/*" multiple = "multiple" size="20" /> <br />
as we can see model part is very short i want to collect images name in array form and send it to database.
You need to save the images in the upload folder and save the image name in the database.
<html>
<body>
<form method="POST" action="<?php echo site_url('my-controller/file_upload');?>" 'enctype'=>'multipart/form-data'>
<label for="file">Filename:</label>
<input type="file" name="userfile[]" id="file" multiple>
<input type="submit" value="upload"></form>
</body>
</html>
Then create controller
make funtion inside it:
$files = $_FILES;
$cpt = count($_FILES['userfile']['name']);
for($i=0; $i<$cpt; $i++)
{
$_FILES['userfile']['name']= $files['userfile']['name'][$i];
$_FILES['userfile']['type']= $files['userfile']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['userfile']['error'][$i];
$_FILES['userfile']['size']= $files['userfile']['size'][$i];
$this->upload->initialize($this->set_upload_options());
$this->upload->do_upload();
$fileName = $_FILES['userfile']['name'];
$images[] = $fileName;
Hope this will help you.
For more you can try this: http://w3code.in/2015/09/upload-file-using-codeigniter/

html POST request login to website

Hi im trying to figure out how to login to a website using a post request.
I want to do this because i want to make a web app using particular data from content shown on the website after login.
However i cannot seem to figure out which url i need to use to login.
This is the FORM :
<FORM onSubmit="return checkrequired(this)" METHOD=POST ACTION="/pkmslogin.form">
<FONT SIZE="+2">
<TABLE BORDER="0" WIDTH="400">
<TR>
<TD ALIGN="LEFT"><UL><LI>Gebruikersnaam</LI></UL></TD>
<TD><INPUT TYPE="TEXT" NAME="username" SIZE="15" AUTOCOMPLETE="off">
</TD>
</TR>
<TR>
<TD ALIGN="LEFT"><UL><LI>Wachtwoord</LI></UL></TD>
<TD><INPUT TYPE="PASSWORD" NAME="password" SIZE="15" AUTOCOMPLETE="off"></TD>
<INPUT TYPE="HIDDEN" NAME="login-form-type" VALUE="pwd">
</TR>
</TABLE>
</FONT>
<BR>&nbsp <INPUT TYPE="SUBMIT" VALUE="Aanmelden">
The javascript checkrequired():
function checkrequired(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (((tempobj.type=="text"||tempobj.type=="password")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==0)) {
pass=false;
break;
}
}
}
if (!pass) {
shortFieldName=tempobj.name.substring(0,30).toUpperCase();
if (shortFieldName=="USERNAME") {
shortFieldName="Gebruikersnaam";
}
if (shortFieldName=="PASSWORD") {
shortFieldName="Wachtwoord";
}
alert("Het veld \""+shortFieldName+"\" is niet ingevuld.");
return false;
}
else
return true;
}
I thought i needed to use /?Username='...'&password='...' but this is not the case.
edit
Chrome developer tools tells me no variables are being passed to the pkmslogin.form
Path = pkmslogin.form
method = POST
Status = 302 Moved Temporarily
type = text/html
Initiator = Other
Size = 713 B 0 B
Time = 367 ms 366 ms
It seems that you are using IBM WebSEAL but instead of using its management page, you made your own
So, the problem is that you are sending the request to /pkmslogin.form but as your application is behind WebSEAL, so it must be accessed by a junction.
So, your request actually goes to:
https://WebSEAL_HOST:WebSEAL_Instance_Port/Your_Junction/Your_App_Context_Root/pkmslogin.form
You have two solution:
Use a relative URL:
../../Your_Junction/pkmslogin.form
Use an absolute URL: https://WebSEAL_HOST:WebSEAL_Instance_Port/pkmslogin.form

How do I get codeIgniter 2, Bradley - SignaturePad and DomPDF to work correctly

Hello: I am using signaturePad [http://thomasjbradley.ca/lab/signature-pad/]and have created a short web form in codeIgniter 2, located here: [http://gentest.lfwebz.com/crd/open_form3], that requires the users to actually sign the form.
I have also installed mPDF and domPDF and I have them working, sort of, but not quite the way I want it to.
The functionality I want is this: User opens web form, fills it out, signs it,
using signPad mentioned above. I then want to click a button that runs mPDF/domPDF and
captures the page and of course the embedded signature.
When I run mpdf/domPDF and pass it the view that houses the form, I think I have figured out it is just grabbing a fresh view, one without the signature, but several parts
of the form are missing. So after digging around, I think I have determined that I have to use image conversion of the signaturePad - this is where I am stuck. I have the code in, using the reference here: Signature pad and dompdf, but it does not work.
If you go to my page here: http://gentest.lfwebz.com/crd/open_form3, sign the page, click the "I accept" button
Here is my view
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../assets/jquery.signaturepad.css" media="screen">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="../jquery.signaturepad.min.js"></script>
</head>
<body>
<?php echo base_url(); ?>
<form method="post" action="<?php echo base_url(); ?>pdf.php" class="sigPad">
<label for="name">Print your name</label>
<input type="text" name="name" id="name" class="name">
<p class="typeItDesc">Review your signature</p>
<p class="drawItDesc">Draw your signature</p>
<ul class="sigNav">
<li class="typeIt">Type It</li>
<li class="drawIt">Draw It</li>
<li class="clearButton">Clear</li>
</ul>
<div class="sig sigWrapper">
<div class="typed"></div>
<canvas class="pad" width="198" height="55"></canvas>
<input type="text" name="output" class="output">
<input type="text" name="imgOutput" class="imgOutput">
</div>
<br /><br /><br />
<button type="submit">I accept the terms of this agreement.</button>
</form>
<script>
var sig;
$( document ).ready( function ( ) {
sig = $('.sigPad').signaturePad({defaultAction:'drawIt'});
} );
$( '.sigPad' ).submit( function ( evt ) {
$( '.imgOutput' ).val( sig.getSignatureImage( ) );
} );
</script>
</body>
</html>
here is the controller or the pdf.php mentioned above:
<?php
if(isset($_POST['imgOutput'])){$img_output = $_POST['imgOutput'];}
echo "position 1";
$bse = preg_replace('#^data:image/[^;]+;base64,#', '', $img_output );
echo "position 2";
echo $bse;
if ( base64_encode( base64_decode( $bse) ) === $bse ) {
require_once 'dompdf/dompdf_config.inc.php';
$html = '<!DOCTYPE html><html><head></head><body><p>Your signature:</p><br /><img src="'. $img_output .'"></body></html>';
$dompdf = new DOMPDF;
$dompdf->load_html( $html );
$dompdf->render( );
$dompdf->stream("test.pdf");
}
else{
echo ("ERROR !");
}
?>
What am I missing here? Please could some one point me in the right direction?
Let me know if you need more info.
Thank you in advance.