0

This code has no error, checked the console no errors, print_r($temp) gives proper result. print_r($_FILES["file"]["tmp_name"]) gives proper result but the values are no stored in the phpMyAdmin Db and in the uploaded_videos dir. The last line is also not printed on the screen

<?php
  include("database_connection.php");
  $allowedExtn = array("mp4","mov","avi","wmv","flv","mpeg");
  $temp = explode(".", $_FILES["file"]["name"]);
  $extension = end($temp);
  $videoname = $_FILES["file"]["name"];



  if((($_FILES["file"]["type"]=="video/mp4")
|| ($_FILES["file"]["type"]=="video/mov")
|| ($_FILES["file"]["type"]=="video/avi")
|| ($_FILES["file"]["type"]=="video/wmv")
|| ($_FILES["file"]["type"]=="video/flv")
|| ($_FILES["file"]["type"]=="video/mpeg"))
&& in_array($extension, $allowedExtn))
  {
 if($_FILES["files"]["error"]>0)
 {
    echo "Error in Uploading video ". $_FILES["file"]["name"];
}

else
{
    move_uploaded_file($_FILES["file"]["tmp_name"], "uploaded_videos/" . 
      $_FILES["file"]["name"]);
    $filepath = "uploaded_videos/" . $_FILES["file"]["name"];
    $query = "INSERT INTO video_upload (username, video_name, video_ext,          
            video_url) VALUES ('Venkat', 'videoname','$extension','$filepath')";
    mysql_query($query);
    print_r($query);
    mysql_close();
    echo "Video " .$videoname . " saved.";
}


  }

 ?>

Can anyone please tell me where is the short coming..??

MixedVeg
  • 319
  • 2
  • 15
  • are you sure the uploaded_videos directory is writeable by your script? – Olli Jun 02 '14 at 11:48
  • how do i find that out.?? I mean I was able to store PDFs and Docs in a directory called upload_resume in a similar way.! – MixedVeg Jun 02 '14 at 11:57
  • depending on the system you are working you might get directory permission information (either on a console/ftp/ssh/whatever client). – Olli Jun 02 '14 at 12:14
  • `echo mysql_error();` right after the query... – Daniel W. Jun 02 '14 at 12:18
  • echo "Video " .$videoname . " saved."; is notworking $videoname is not getting printed, echo "hi" and echo echo mysql_error() showing no error – MixedVeg Jun 02 '14 at 12:43

2 Answers2

1

If you are on linux and have access to the filesystem then check the permissions and ownership of the uploaded_videos directory (use ls -la or similar) if you need to change them then look up chmod and chown or use your cpanel? interface.

  • Make sure also that the directory exists where you think it does (in the same directory as the script you are running).
  • The first task to sort out is the writing to disk - I'd suggest commenting out the mysql for now.
  • Also try it with a small file that has a shortish filename with no funny characters or spaces first.
  • Turn on error reporting in your script error_reporting(E_ALL); ini_set('display_errors',true)
  • and check the return value of move_uploaded_file
  • if it is false with no errors then check the file
  • if it is false with errors then check the filesystem (and the errors)
soqls
  • 26
  • 5
  • hey @soqls, I am using Windows. yes the directory exists in my project folder in htdocs (where the index etc files are present). – MixedVeg Jun 02 '14 at 12:49
  • error_reporting(E_ALL); this is what i read to enable all error reporting but no error is shown.. :( – MixedVeg Jun 02 '14 at 12:55
  • display_startup_errors=On and display_errors = On and error_reporting(E_ALL); no result – MixedVeg Jun 02 '14 at 12:58
  • ok - try var_dumping $_FILES to see that all is in order (filesize not bigger than php.ini settings, named ok etc. try writing any file to that directory. try a 3 letter file extension as a test as well (make it as simple as possible to test). Check you've enough disk space. Also just for assurance run getcwd() to see what directory it thinks this script is in - and use that to ensure it's trying to write to file where you think it is. – soqls Jun 02 '14 at 13:29
  • array(1) { ["file"]=> array(5) { ["name"]=> string(10) "video1.flv" ["type"]=> string(24) "application/octet-stream" ["tmp_name"]=> string(24) "C:\xampp\tmp\php6B96.tmp" ["error"]=> int(0) ["size"]=> int(9745167) } } – MixedVeg Jun 02 '14 at 14:04
  • your file type is application/octet-stream and you're filtering on video/flv – soqls Jun 02 '14 at 14:12
  • if you're on php 5.3 + then try something like: $finfo = new finfo(FILEINFO_MIME); echo $finfo->file($_FILE['file']['tmp_name']); – soqls Jun 02 '14 at 14:45
  • video/x-flv; charset=binary This is the result, flv type that means.!! – MixedVeg Jun 03 '14 at 04:47
  • ...thanks alot I was able to debug the things and find my way out...everything is working now and every video type is getting uploaded..Cheers..!! – MixedVeg Jun 03 '14 at 12:51
1

First of all use MySQLI or PDO for your queries.

 $insertQuery = " INSERT INTO `databaseName`.`tableName` (`username`,`video_name`,`video_ext`, `video_url`) VALUES ('Venkat','videoname','$extension','$filepath') ";

 $insertQueryResult = $connector->query($insertQuery);

I think you should put the

$filepath = 'uploaded_videos/'.$_FILES['file']['name'];

below of the :

$videoname = $_FILES['file']['name'];

This is just a simple sample for using MySQLI. You can refer to THIS LINK

user3437929
  • 61
  • 11