php mysql上传视频_使用PHP / MySQL将视频上传到文件夹中,并将其链接到数据库

这篇博客讲述了如何使用PHP和MySQL将视频上传到服务器上的特定文件夹,并将视频路径保存到数据库中。作者遇到了视频无法插入指定文件夹的问题,分享了尝试过的代码,并提供了完整的文件上传解决方案,包括创建HTML表单、PHP文件上传代码以及大小限制和文件类型的检查。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

bd96500e110b49cbb3cd949968f18be7.png

I am trying to upload a video and save it in a folder as well as savings its path in the database, but the videos are not inserting into the specific folder.

I have searched a lot and found some code. The code is working for images. I have done some modifications from images to videos, but that didn't work.

Here is the parts of my code.

and my php code to upload video is

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 am going wrong.

All my php.ini modifications are done, and video size is only 7mb.

解决方案

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 choose the file they want to upload.

Please choose a file:

This form sends data to the file "upload.php", which is what we will be creating next to actually upload the file.

Step-2

The actual file upload is very simple:

$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 upload files sent to it by 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

upload files to www.yours.com/files/upload/yourfile.gif. Be sure you remember to create

this folder! with 777 rights

Step-3

if ($uploaded_size > 350000)

{

echo "Your file is too large.
";

$ok=0;

}

Assuming that you didn't change the form field in our HTML form (so it is still named uploaded), this will check to see the size of the file. If the file is larger than 350k, they are given a file too large error, and we set $ok to equal 0.

You can change this line to be a larger or smaller size if you wish by changing 350000 to a different number. Or if you don't care about file size, just leave these lines out

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 All Together

$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.
";

$ok=0;

}

//This is our limit file type condition

if ($uploaded_type =="text/php")

{

echo "No PHP files
";

$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 are allowing file uploads you are leaving yourself open to people uploading lots of undesirable things. One precaution is not allowing them to upload any php, html, cgi, etc. files that could contain malicious code. This provides more safety but is not sure fire protection.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值