0

我正在尝试上传视频并将其保存在文件夹中,并将其路径保存在数据库中,但视频并未插入到特定文件夹中。

我搜索了很多并找到了一些代码。该代码适用于图像。我做了一些从图像到视频的修改,但没有奏效。

这是我的代码的一部分。

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

我上传视频的php代码是

<?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";
}

}

?>

请帮助我哪里出错了。

我所有的php.ini修改都完成了,视频大小只有 7mb。

4

3 回答 3

2

步骤1

该脚本将允许您使用 PHP 将文件从浏览器上传到主机。我们需要做的第一件事是创建一个 HTML 表单,允许人们选择他们想要上传的文件。

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

此表单将数据发送到文件“upload.php”,这是我们接下来将创建的文件以实际上传文件。

第2步

实际的文件上传非常简单:

<?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.";
 }
 ?> 

这段非常小的代码将上传您的 HTML 表单发送给它的文件。

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 

将文件上传到 www.yours.com/files/upload/yourfile.gif。请务必记住创建此文件夹!拥有777个权利

第三步

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

假设您没有更改我们 HTML 表单中的表单字段(因此仍然命名为已上传),这将检查文件的大小。如果文件大于 350k,则会给出文件太大的错误,我们将 $ok 设置为 0。

如果您愿意,可以通过将 350000 更改为不同的数字来将此行更改为更大或更小的尺寸。或者,如果您不关心文件大小,请忽略这些行

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.

放在一起

<?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."; 
 } 
 } 
 ?>

显然,如果您允许文件上传,您就会让自己对上传许多不受欢迎的东西的人开放。一项预防措施是不允许他们上传任何可能包含恶意代码的 php、html、cgi 等文件。这提供了更多的安全性,但不确定防火。

于 2013-11-15T06:53:18.673 回答
0

试试这个: $_FILES['userfile'] 代替 $_FILES['uploadvideo'] 无处不在。

于 2013-11-15T06:37:12.037 回答
0

uploadvideo我在你的表格中没有看到任何名字。

但是在php中你正在使用$_FILES['uploadvideo']

尝试给出文件输入的确切名称

例如:

<input type="file" name="uploadvideo">
于 2013-11-15T06:38:49.920 回答