0

I've tried to make a form for uploading pictures and videos and renaming them with a specific id from mysql.

The data is stored in mysql, the picture is uploading but video is not uploaded. Could somebody tell me where is wrong?

form code:

<form id='adaugaanunt' name='add-item' method='post' action='add_in_video.php'     enctype='multipart/form-data' onsubmit="return jcap();">
<div class='container'>
<label for='titlu' >*Titlu:</label><br />
<input name='titlu' required='required' placeholder='ex. Vand ceas ROLEX' type='text'  class='input required' /></div><br />
<div class='container'>
<label for='descriere' >*Descriere:</label><br />
<input name='descriere' required='required' placeholder='ex. Vand ceas ROLEX cu luminite' type='text' class='input required' /></div><br />
<div class='container'>
<label for='pic1' >Poza: </label><br />
<input name='pic1' type='file' /><br />
</div><br />
<div class='container'>
<label for='vid1' >Video: </label><br />
<input name='vid1' type='file' /><br />
</div><br />
<div class='container' style="float:right"><input name='submit' type='submit' value='Trimite' /></div>
<div class='container' style="float:left"><input type="reset" name="Reseteaza" value="Reseteaza"></div>
</form>

add_in_video.php

<?php include 'include/global.php'; 
$titlu = str_replace("'","`",$_POST['titlu']);
$cere = "SELECT * FROM `video` WHERE titlu='".$titlu."'";
$rez = mysql_query($cere);
$cnt = mysql_num_rows($rez);
if ($cnt == 0) {
$title = htmlentities($titlu);
$descriere = htmlentities($_POST['descriere']);
$cerereSQL = "INSERT INTO `video` (`id` , `titlu`, `descriere`)
VALUES ('', '$titlu', '$descriere')";
//echo $cerereSQL;
$result_insert_user = mysql_query($cerereSQL);
if (file_exists("../videos/".mysql_insert_id()."a.jpg"))
{
unlink("../videos/".mysql_insert_id()."a.jpg");
}
if (file_exists("../videos/".mysql_insert_id()."b.avi"))
{
unlink("../videos/".mysql_insert_id()."b.avi");
}
if ($_FILES["pic1"]["name"] != "") {
if (($_FILES["pic1"]["type"] == "image/gif") || ($_FILES["pic1"]["type"] == "image/jpeg") || ($_FILES["pic1"]["type"] == "image/pjpeg") || ($_FILES["pic1"]["type"] == "image/bmp"))
{
if ($_FILES["pic1"]["error"] > 0)
{
echo "A intervenit o eroare: " . $_FILES["pic1"]["error"] . "<br />";
}
else
{
if (file_exists("../videos/" . $_FILES["pic1"]["tmp_name"]))
  {
  echo "Poza exista deja";
  }
 else
  {
  move_uploaded_file($_FILES["pic1"]["tmp_name"], "../videos/".mysql_insert_id()."a.jpg");
  }
 }
 }
else
{
header('Location: '.$domain.'index.php');
exit;
}
}

if ($_FILES["vid1"]["name"] != "") {
$allowedExts = array("wmv","avi","mpeg","mpg", "mp4");
$extension = end(explode(".", $_FILES["vid1"]["name"]));
if ((($_FILES["vid1"]["type"] == "video/mp4") || ($_FILES["vid1"]["type"] == "video/wmv") || ($_FILES["vid1"]["type"] == "video/mpg") || ($_FILES["vid1"]["type"] == "video/mpeg")) && in_array($extension, $allowedExts))
 {
if ($_FILES["vid1"]["error"] > 0)
{
echo "A intervenit o eroare: " . $_FILES["vid1"]["error"] . "<br />";
}
else
{
if (file_exists("../videos/" . $_FILES["vid1"]["tmp_name"]))
  {
  echo "Acest video exista deja";
  }
else
  {
  move_uploaded_file($_FILES["vid1"]["tmp_name"], "../videos/".mysql_insert_id()."b.avi");
    }
   }
 }
else
{
header('Location: '.$domain.'index.php');
exit;
}
}



} else {
header('Location: '.$domain.'index.php');
exit;
}
?>

I dont recieve any error message. The image file is uploading and the video file is NOT UPLOADING. Sorry about this code, Im new to PHP/MYSQL. I need to store that files local, because I have a videoplayer that is populated from that folder.

4

1 回答 1

0

确保错误代码实际上为零(这是文件不存在的第一个原因)。如果它不为零,那么您可以找到有关错误代码PHP 的信息 - 错误消息解释

您应该检查 move_uploaded_file 的返回值:

$tmp_name = $_FILES["vid1"]["tmp_name"];
$name = "../videos/" . mysql_insert_id() . "b.avi";
if(!move_uploaded_file($tmp_name, $name)){
    print "Could not move file $tmp_name to $name<br>";
} else {
    print "Successfully copied files<br>";
}

move_uploaded_file 调用中可能存在错误,随后的警告被 PHP 抑制

error_reporting(E_ALL);您可以通过在脚本开头调用来打印所有错误/警告/消息。此处有关错误报告的更多信息 - PHP - error_reporting

于 2013-06-11T22:51:55.970 回答