Uploading video to a folder and its link to the database using php

I am trying to upload a video and save it in a folder and its path in the database. But videos are not pasted into a specific folder. I searched a lot and found the code. Code works for images. I made some changes from images to videos, but that didn't work. Here is part of my code.

<form action="" method="post" enctype="multipart/form-data"> <div class="form_search"> <label>Upload Video Profile:</label> <span class="form_input"> <input type="file" name="uploadvideo" /> </span> </div> <div class="form_search"> <label> &nbsp;</label> <span class="form_input"> <input type="submit" name="submitdetails" value="Upload" class="button"/> </span> </div> </form> 

and my php code to upload the video

 <?php if(isset($_POST['submitdetails'])) { $name=$_FILES['uploadvideo']['name']; $type=$_FILES['uploadvideo']['type']; //$size=$_FILES['uploadvideo']['size']; $cname=str_replace(" ","_",$name); $tmp_name=$_FILES['uploadvideo']['tmp_name']; $target_path="company_profile/"; $target_path=$target_path.basename($cname); if(move_uploaded_file($_FILES['uploadvideo']['tmp_name'],$target_path)) { echo "hi"; echo $sql="UPDATE employer_logindetails SET (video) VALUES('".$cname."')"; $result=mysql_query($sql); echo "Your video ".$cname." has been successfully uploaded"; } } ?> 

Please help me where I go wrong. All my php.ini modifications have been completed, and the video size is only 7 MB.

0
source share
3 answers

Try the following: $ _FILES ['userfile'] instead of $ _FILES ['uploadvideo'] everywhere.

0
source

I do not see any name with uploadvideo in your form.

But in php you use $_FILES['uploadvideo']

Try to specify the exact file input name

eg:

 <input type="file" name="uploadvideo"> 
0
source

Step 1

This script will allow you to upload files from your browser to your hosting using PHP. The first thing we need to do is create an HTML form that allows people to select the file they want to upload.

  <form enctype="multipart/form-data" action="upload.php" method="POST"> Please choose a file: <input name="uploaded" type="file" /><br /> <input type="submit" value="Upload" /> </form> 

This form sends data to the file "upload.php", which we will create next to the actual file upload.

Step 2

Actual file download is very simple:

 <?php $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } ?> 

This very small piece of code will download files sent to it in your HTML form.

 The first line $target = "upload/"; is where we assign the folder that files will be uploaded to. As you can see in the second line, this folder is relative to the upload.php file. So for example, if your file was at www.yours.com/files/upload.php then it would 

Download files at www.yours.com/files/upload/yourfile.gif. Do not forget to create this folder! with rights 777

Step 3

  if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } 

Assuming you have not changed the form field in our HTML form (so that it is still loaded by name), this will check to see the file size. If the file is larger than 350k, it is given a file error that is too large, and we set the value of $ ok to 0.

You can change this line to a larger or smaller size if you want by changing 350,000 to another number. Or, if you do not need the file size, just leave these lines

 We are not using $ok=1; at the moment but we will later in the tutorial. We then move the uploaded file to where it belongs using move_uploaded_file (). This places it in the directory we specified at the beginning of our script. If this fails the user is given an error message, otherwise they are told that the file has been uploaded. 

Putting everyone together

 <?php $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } ?> 

Obviously, if you allow file downloads, you leave yourself open to people downloading a lot of unwanted things. One precaution does not allow them to upload php, html, cgi, etc. files that may contain malicious code. This provides greater security, but is not a reliable fire protection.

0
source

Source: https://habr.com/ru/post/927084/


All Articles