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, I
m new to PHP/MYSQL.
I need to store that files local, because I have a videoplayer that is populated from that folder.