Jump to content

Why do i get error, file uploading ?


jd2007

Recommended Posts

<?php
class FlashUploader
{
  private $host;
  private $username;
  private $password;
  private $db;
  private $table;
  private $title;
  private $brief;
  private $main;
  private $checkboxes;
  private $flash;
  private $flashtype;
  private $flashsize;
  private $flashtmp;
  //private $thumb;
  private $author;
  private $submitted;
  private $score;
  private $size;

  function connectdb($l, $u, $p, $d)
{
      $this->host=$l;
      $this->username=$u;
  $this->password=$p;
  $this->db=$d;
  mysql_connect($this->host, $this->username, $this->password);
  mysql_select_db($this->db);
}

  function getandsendDetails($ftitle, $fbrief, $fmain, $fcbx, $aut, $subm, $sc)
{
  $this->checkboxes=explode("/", $fcbx);
      $this->que="insert into videos (title, brief, main, author, submitted, size) values ($this->title, $this->brief, $this->main, $this->author, $this->submitted, $this->size)";
  $this->res=mysql_query($this->que);
}

function checkFiles($file, $filetype, $filesize, $filetmp)
{ 
	echo $this->flash=$file;
              echo $this->flashtype=$filetype;
             $this->flashsize=$filesize;
	echo $this->flashtmp=$filetmp;
	/*
	$this->thumb=$thumbnail;
	$this->thumbtype=$thumbnailtype;
        $this->thumbsize=$thumbnailsize;
	$this->thumbtmp=$thumbnailtmp;*/

      if (is_uploaded_file($this->flash))
	{
           if (filetype($this->flashtype)=="application/x-shockwave-flash")
		{
              if (filesize($this->flashsize)>=3000000)
		 {
              echo "Flash is good !";
		 }
		 else
		 {
              echo "Flash too large.";
		 }
		}
		else
		{
              echo "Flash not valid type.";
		}
	}
      else
	{
          echo "Flash doesn't exist.";
	}
}

function moveFiles()
{
      move_uploaded_file($this->flashtmp, "a/");
}
}

$flashupload=new FlashUploader;
$flashupload->connectdb("localhost", "root", "*****", "videoportal");
$x=$flashupload->checkFiles($_FILES["filef"]["name"], $_FILES["filef"]["type"], $_FILES["filef"]["size"], $_FILES["filef"]["tmp_name"]);
if ($x=="Flash is good !")
{
$y=$flashupload->moveFiles();
if (!$y)
{
  echo "File could not be uploaded";
}
else
{
$flashupload->getandsendDetails($_POST["textfield4"], $_POST["textfield5"], $_POST["textfield52"], $_GET["arr"], "jd2007", "2", "0");
}
}
else
{
echo $x;
print_r(error_get_last());
}
?>

 

i get this output:

 

Luciano Pavarotti and Elton John - Live Like Horses.mp3Flash doesn't exist.Array ( [type] => 8 [message] => Undefined variable: flashtmp [file] => C:\AppServ\www\a\flashportal\flash_upload.php [line] => 46 )

Link to comment
https://forums.phpfreaks.com/topic/64835-why-do-i-get-error-file-uploading/
Share on other sites

Is there anything wrong in my code below- the file is not uploading?

 

function moveFiles()
{
  move_uploaded_file($this->flashtemp,"C:\AppServ\www\a\flashportal\flash");
}

 

$this->flashtemp is $_FILES["filef"]["tmp_name"].

i want to upload in folder 'flash'.

pls help...

 

here is my code updated:

 

<?php
class FlashUploader
{
  private $a=0;
  private $host;
  private $username;
  private $password;
  private $db;
  private $table;
  private $title;
  private $brief;
  private $mainx;
  private $checkboxes;
  private $flash;
  private $flashtype;
  private $flashsize;
  private $flashtemp;
  private $author;
  private $submitted;
  private $score;
  private $size;
  private $que;
  private $res;

  function connectdb($l, $u, $p, $d)
{
      $this->host=$l;
      $this->username=$u;
  $this->password=$p;
  $this->db=$d;
  mysql_connect($this->host, $this->username, $this->password);
  mysql_select_db($this->db);
}

  function getandsendDetails($ftitle, $fbrief, $fmain, $fcbx, $aut, $subm, $sc)
{
  $this->title=$ftitle;
  $this->brief=$fbrief;
      $this->mainx=$fmain;
      $this->author=$aut;
  $this->submitted=$subm;
  $this->score=$sc;
  $this->checkboxes=explode("/", $fcbx);
      echo $this->que="insert into videos (title, brief, main, author, submitted, size, score) values ('$this->title', '$this->brief', '$this->mainx', '$this->author', '$this->submitted', '$this->flashsize', '$this->score')";
  $this->res=mysql_query($this->que);
}

function checkFiles($file, $filetype, $filesize, $filetmp)
{ 
	$this->flash=$file;
         $this->flashtype=$filetype;
        $this->flashsize=$filesize;
         echo $this->flashtemp=$filetmp;

     if (is_uploaded_file($this->flashtemp))
	{
           if ($this->flashtype=="application/x-shockwave-flash")
		{
              if ($this->flashsize<3000000)
		 {
              echo "1";
		 }
		 else
		 {
              echo "Flash too large.";
		 }
		}
		else
		{
              echo "Flash not valid type.";
		}
	}
      else
	{
          echo "Flash doesn't exist.";
	}
}

function moveFiles()
{
      move_uploaded_file($this->flash,"C:\AppServ\www\a\flashportal\flash");
}
}

$flashupload=new FlashUploader;
$flashupload->connectdb("localhost", "root", "*****", "videoportal");
$flashupload->checkFiles($_FILES["filef"]["name"], $_FILES["filef"]["type"], $_FILES["filef"]["size"], $_FILES["filef"]["tmp_name"]);
$flashupload->moveFiles();
$flashupload->getandsendDetails($_POST["textfield4t"], $_POST["textfield5t"], $_POST["textfield52t"], $_GET["arr"], "jd2007", "12-09-2007 12:21:30", "2");

?>

Try:

 

move_uploaded_file($this->flash,"C:\AppServ\www\a\flashportal\flash\".basename($_FILES['filef']['name']));

 

By the way, your checkFiles method is verifying the mime type with $_FILES["filef"]["type"] which is not to be trusted since that is determined by the browser which only checks the file extension and not the file header/content. You may want to check out the PECL fileinfo extension.

  • 2 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.