upload video file using php - php

I am trying to upload file using php and i get error of form not submit whenever everything is right according to me below is the code video upload form
<form action="tek.php" method="POST" enctype="multipart/form-data">
<input type="text" name="name" placeholder="Name"><br/>
<input type="text" name="mobile" placeholder="Mobile No."><br/>
<input type="file" name="videouser" ><br/>
<input type="file" name="audiouser" ><br/>
<input type="submit" name="submit" value="Submit">
</form>
and below is my tek.php page code
if(isset($_POST["submit"])){
$name = $_POST["name"];
$mobile = $_POST["mobile"];
$video_dir = "admin/video/";
$temp = explode(".", $_FILES["videouser"]["name"]);
$newfilename = round(microtime(true)) . '.' . end($temp);
move_uploaded_file($_FILES["videouser"]["tmp_name"], "/admin/video/" .$newfilename)or die("not uploading a video");
$videofile = rand() . basename($_FILES["videouser"]["name"]);
if(move_uploaded_file($_FILES["videouser"]["name"], $video_dir.$newfilename))
{
echo "upload video successfull";
}else{
echo "video file not uploaded";
}
$audio_dir = "admin/audio/";
$audiofile = rand() . basename($_FILES["audiouser"]["name"]);
if(move_uploaded_file($_FILES["audiouser"]["name"], $audio_dir.$audiofile) or die("Not Uploaded audio"))
{
echo "upload audio successfull";
}else{
echo "audio file not uploaded";
}
}else{
echo "form not submitted.";
}
above code of tek.php page work fine for image but not for video or audio file i also increase limit post_max_size = 500M and upload_max_size = 500M where i make mistake don't know please help thanks in advance.

Change following codes:
if(move_uploaded_file($_FILES["videouser"]["tmp_name"], $video_dir.$newfilename))
{
echo "upload video successfull";
}else{
echo "video file not uploaded";
}
$audio_dir = "admin/audio/";
$audiofile = rand() . basename($_FILES["audiouser"]["name"]);
if(move_uploaded_file($_FILES["audiouser"]["tmp_name"], $audio_dir.$audiofile) or die("Not Uploaded audio"))
{
echo "upload audio successfull";
}else{
echo "audio file not uploaded";
}
you should use tmp_name instead of name in the move process

Hi Friends i got the answer
1. first configure your php.ini
2. if you use wamp then you get php.ini in wamp/bin/php/php7.0.10(php version)/php.ini
3. set in php.ini
post_max_size = 10240M
upload_max_filesize = 500M
4. Restart Your wamp server(must)
now the code to upload video below in upload.php
<?php
if(isset($_FILES['file'])){
$errors= array();
$file_name = $_FILES['file']['name'];
$file_size =$_FILES['file']['size'];
$file_tmp =$_FILES['file']['tmp_name'];
$file_type =$_FILES['file']['type'];
if (!file_exists('uploaded_here')) { // file will be uploaded in this folder
mkdir('uploaded_here', 0777, true);
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"uploaded_here/".$file_name);
echo "Uploaded in folder uploaded_here file name is : ".$file_name;
}else{
echo "Not Uploaded";
}
}
?>
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="post" enctype="multipart/form-data">
<input type="file" name="file" accept="file_extension|audio/*|video/*|image/*|media_type">
<br>
<input type="submit" value="Upload">
</form>
its working for me

Related

i think move uploaded file is not working even though he can find if the file is existed

If i choose in the same folder of my target directory it said file exist but when i choose in different folder it said success but there`s no file uploaded in that folder here is my code. i get it in google
<?php
if (($_FILES['my_file']['name']!="")){
// Where the file is going to be stored
$target_dir = "/home/cidinc1802/Pictures/";
$file = $_FILES['my_file']['name'];
$path = pathinfo($file);
$filename = $path['filename'];
$ext = $path['extension'];
$temp_name = $_FILES['my_file']['tmp_name'];
$path_filename_ext = $target_dir.$filename.".".$ext;
if (file_exists($path_filename_ext)) {
echo "Sorry, file already exists.";
}else{
move_uploaded_file($temp_name,$path_filename_ext);
echo "Congratulations! File Uploaded Successfully.";
}
}
?>
<form name="form" method="post" action="fortesting.php" enctype="multipart/form-data" >
<input type="file" name="my_file" /><br /><br />
<input type="submit" name="submit" value="Upload"/>
</form>

uploading video file not working

I want to upload video files in php for that i am using following code
PHP
$newUploadDir = "c://video";
$idx = "file";
if (isset($_FILES[$idx]) && is_array($_FILES[$idx])) {
echo "file set";
foreach ($_FILES[$idx]["error"] as $key => $error) {
echo "loop";
if ($error == UPLOAD_ERR_OK) {
echo "<br/>dd2";
$tmp_name = $_FILES[$idx]["tmp_name"][$key];
$name = $_FILES[$idx]["name"][$key];
$ext1 = explode(".", $name);
$extension = end($ext1);
$newfilename = "test".".".$extension;
$video_types = array('mp4', 'avi','webm');
if (in_array($extension, $video_types)) {
if (move_uploaded_file($tmp_name, $newUploadDir.$newfilename)) {
echo "uploaded to folder";
} else {
echo "Not uploaded to folder";
}
}
} else {
echo "not uploaded $error";
}
}
}
echo "ok";
HTML
<form action="http://localhost/fileupload/video.php" enctype="multipart/form-data" method="post">
<input id="file1" name="file[]" type="file"/>
<input name="userId" type="text" value="2"/>
<input id="Submit" name="submit" type="submit" value="Submit" />
</form>
Output
file setloopnot uploaded 1ok
Video file is not uploading. How to resolve this?
Actually, if you try to upload very large (video) files, probably the upload file size limit will not let you do that. Instead of regular file upload, there are other possibities. For the begining, look at this, this or this.
An other aproach would be to use third party services like Amazon S3, Microsoft Azure, etc.

move_upload_file() is not working

<?php
if (isset($_FILES['file']['name'])){
$name = $_FILES['file']['name'];
$tmp_name = $_FILES['file']['tmp_name'];
$location = 'uploads/';
if (!empty($name)){
if(move_uploaded_file($tmp_name, $location.$name)){
echo 'Uploaded successful';
}
}else
echo 'Please select a file.';
}?>
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file"><br><br>
<input type="submit" value="Submit">
</form>
I am not getting any error but the move_uploaded_file() is not working. It displayed no result on the browser. I have the folder 'uploads/' inside my directory.
The problem is solved, the maximum file size for the file to be uploaded is 2MB. The file that I tried to upload exceed 0.1MB. Thank all of you.

PHP trying to move file with move_uploaded_file

I have been back forward about this, can't find a solution. My file that I am trying to upload is not moving. I'm using WAMP and my root folder is C:\wamp\www
I've checked that the directory exists in php and put in a script that if it does not exist it should be created, which works, but still it is not moving the file. What am I doing wrong?
The Form:
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
Upload.php
$target_path = "uploads/" ;
if(!file_exists($target_path)) {
mkdir($target_path, 0755, true);
echo "The directory was created";
}
$tmp_name = $_FILES['file']['tmp_name'];
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
echo $target_path;
if(move_uploaded_file($tmp_name, $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
try to change,
$tmp_name = $_FILES['file']['tmp_name'];
to
$tmp_name = $_FILES['uploadedfile']['tmp_name'];

file uploaded successfully but I can't find the file

I'm using Azure server to open the website and linking to dropbox to store all the code files. I have an folder called 'image' but after uploading, though it shows "Uploaded!", I can't find that file.
Here's my code:
<?php
$name = $_FILES['file']['name'];
$size = $_FILES['file']['size'];
$type = $_FILES['file']['type'];
$tmp_name = $_FILES['file']['tmp_name'];
$error = $_FILES['file']['error'];
if (isset($name)){
if(!empty($name)){
$location = 'image/';
if(move_uploaded_file($tmp_name, $location.$name)){
echo 'Uploaded!';
}else{
echo 'There was an error.';
}
}else{
echo 'Plz choose a file.';
}
}
?>
<form action="add.php" method="post" enctype="multipart/form-data">
Select file to upload:
<input type="file" name="file" id="file">
<input type="submit" value="Upload Image" name="submit">
</form>
Your uploaded file is in the image folder that is in the same folder of your page.php.
See your code:
$location = 'image/';
if(move_uploaded_file($tmp_name, $location.$name)){
The final location of your file is $location.$name. This is image/your_file_name.your_extension

Categories