I have downloaded and implemented Uploadify because users were tired of having to browse to each and every file they needed to upload(since this is used for uploading multiple pictures) allows a user to select multiple pictures at once without having to click a "BROWSE" button to go fetch each picture. The problem is, I NEED to use MY upload.php script in order for it to meet the needs of my project. However, i'm not all that great at php, and it took me hours to get my own upload script to work. Now, I don't know how to get what I have written to work with uploadify.

Here is uploadify's default script:

<?php
if (!empty($_FILES)) {
	$tempFile = $_FILES['Filedata']['tmp_name'];
	$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
	$targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
	
	// $fileTypes  = str_replace('*.','',$_REQUEST['fileext']);
	// $fileTypes  = str_replace(';','|',$fileTypes);
	// $typesArray = split('\|',$fileTypes);
	// $fileParts  = pathinfo($_FILES['Filedata']['name']);
	
	// if (in_array($fileParts['extension'],$typesArray)) {
		// Uncomment the following line if you want to make the directory if it doesn't exist
		// mkdir(str_replace('//','/',$targetPath), 0755, true);
		
		move_uploaded_file($tempFile,$targetFile);
		echo "1";
	// } else {
	// 	echo 'Invalid file type.';
	// }
}
?>

And here is my script that I must use:

<?php
  if (isset($_POST['upload'])) {
  $con = mysql_connect("localhost", "xxx", "xxx") or die("cannot connect");
  mysql_select_db("xxx", $con) or die("cannot select DB");
      $img = $_FILES["image"]["name"];
      foreach ($img as $key => $value) {
          $name = $_FILES["image"]["name"][$key];
          $tname = $_FILES["image"]["tmp_name"][$key];
          $size = $_FILES["image"]["size"][$key];
          $oext = getExtention($name);
          $ext = strtolower($oext);
          $base_name = "uploads/".getBaseName($name).".$ext";
	   $whois = $_SERVER['REMOTE_ADDR'];
          if ($ext == "jpg" || $ext == "jpeg" || $ext == "bmp" || $ext == "gif") {
              if ($size < 1024 * 1024) {
                  if (file_exists("uploads/" . $name)) {
                      move_uploaded_file($tname, "uploads/" . $name);
                      $result = 1;
                      //list($width, $height) = getimagesize("uploads/" . $name);
                      $qry = "select id from img where img_base_name='$base_name' and img_ext='$ext'";
                      $res = mysql_fetch_array(mysql_query($qry));
                      $id = $res['id'];
                      $qry = "UPDATE pictures SET path='$base_name', type='$ext', size='$size', date=NOW() where id=$id";
                      mysql_query($qry);
                      ?><div style="float:right; text-align:left; width:400px;"><?php echo "Image '$name' <font color='blue'>updated</font><br />";
                  } else {
                      move_uploaded_file($tname, "uploads/" . $name);
                      $result = 1;
                      //list($width, $height) = getimagesize("uploads/" . $name);
                      $qry = "INSERT INTO pictures(id, path, type, size, email, whois, date) VALUES ('', '$base_name', '$ext', '$size', 'xxx', '$whois', NOW())";
                      mysql_query($qry, $con);
                      //Error Checking off by default. Uncomment if you run into problems.
                      //mysql_error();
                      //print_r($qry);
                      ?><div style="float:right; text-align:left; width:400px;"><?php echo "Image '$name' <font color='green'>uploaded</font><br />";
                  }
              } else { 
                  ?><div style="float:right; text-align:left width:400px;"><?php echo "<font color='red'><B>Image size excedded.<br />File size should be less than 1Mb</B></font><br />";
              }
          } else {
              ?><div style="float:right; text-align:left; width:400px;"><?php  echo "<font color='red'><B>Invalid file extention '.$oext'</B></font><br />";
          }
      }
  }
  function getExtention($image_name)
  {
      return substr($image_name, strrpos($image_name, '.') + 1);
  }
  function getBaseName($image_name)
  {
      return substr($image_name, 0, strrpos($image_name, '.'));
  }
?>

Any help is VERY appreciated!

Member Avatar for P0lT10n

Hello, I didn't understand what is your problem... can you explain better ???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.