Make directory with php and pdf with  FPDF

tikkanen
tikkanen used Ask the Experts™
on
I have form where user can upload file and it moved to upload folder with certain name. How is possible to make subfolder inside of this upload folder, rename it and put all files inside of this new folder? I make also textarea where user can wite text (textarea name="memo"), how is possible to make pdf of this memo-textarea and put it also in this new folder. I have tried with FPDF, but it doesn't work.

Here is my send page:

<form  name="tstest" onsubmit="return validate_form(this)" enctype="multipart/form-data" action="action.php" method="POST">
file <input name="uploaded_file" type="file"><br>
name <input name="sender" type="text"><br>
memo <textarea name="memo" id="memo"></textarea>
<br>
<br>
<input type="submit" name="start_upload" value="Lataa tiedosto"/>
</form>

action.php
<?php
// Check that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0))
{
        $filename = basename($_FILES['uploaded_file']['name']);
        $ext = substr($filename, strrpos($filename, '.') + 1);
        if (($ext == "tif" ||$ext == "ps" || $ext == "eps" || $ext == "ai" || $ext == "sit" || $ext == "ZIP" || $ext == "zip" || $ext == "pdf") && ($_FILES["uploaded_file"]["type"] == "application/x-pdf" || $_FILES["uploaded_file"]["type"] == "application/acrobat" || $_FILES["uploaded_file"]["type"] == "applications/vnd.pdf" || $_FILES["uploaded_file"]["type"] == "text/pdf" || $_FILES["uploaded_file"]["type"] == "text/x-pdf" || $_FILES["uploaded_file"]["type"] == "image/tiff" || $_FILES["uploaded_file"]["type"] == "application/postscript" || $_FILES["uploaded_file"]["type"] == "application/x-stuffit" ||$_FILES["uploaded_file"]["type"] == "application/x-zip-compressed" ||$_FILES["uploaded_file"]["type"] == "application/pdf") && ($_FILES["uploaded_file"]["size"] ))
        {
            // Determine the path to which we want to save this file
// here comes new name, is this possible to use with this new folder name.
           $newname = dirname(__FILE__).'/upload/'.$_POST['sender'] .'_' . date('dmY') .'_' . $filename;
            // Check if the file with the same name is already exists on the server
            if (!file_exists($newname))
            {
                  // Attempt to move the uploaded file to it's new place
                  if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname)))
                  {

// here comes new name, is this possible to use with this new folder name.
                   $newname = dirname(__FILE__).'/upload/'.$_POST['sender'] .'_' . date('dmY') .'_' . $filename;
                  echo "Tiedosto ".$_FILES["uploaded_file"]["name"]." on ladattu palvelimelle. ";
                  echo "<BR/>";echo "<BR/>";
                  } else {
                        echo "errormessage";
                        exit();
                        }
                    } else {
                         echo "errormessage";
                         exit();
                    }
        } else {
             echo "errormessage";
             echo "<BR/>"; echo $ext;
             echo "<BR/>"; echo $filename;
             exit();
        }
} else {
echo "Image Uploaded: No";
echo "<BR/>";echo "<BR/>";
}
//email reminder
$message = "Ladattu tiedosto: {$newname}<br />";
$message .= "Tilaajan nimi: {$_POST['sender']}<br />";
$subject = "Tiedosto on ladattu Printstudion palvelimelle";
require("class.phpmailer.php");
$mail = new PHPMailer();

//$mail->Host     = "smtp.eunet.fi";
//$mail->Mailer   = "smtp";
$mail->From = "";
$mail->FromName = "Latauslomake";
$mail->AddAddress("xxx@xxx.com");
$mail->SetLanguage('en', '/language/');
$mail->IsHTML(True);
$mail->Subject  =  $subject; //
$mail->Body     =  $message;
if(!$mail->Send())
{
} else {
}
?>
<html>
  <head>
  </head>
  <body>
  </body>
<html>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Now ican make folder, which is sama name as sender, but how i can direct into this new folder. I try next line but i get an error message: Parse error: syntax error, unexpected T_VARIABLE in c:\inetpub\wwwroot\uploader2.php on line 18

// Check that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0))
{
      
      $kansio = $_POST['sender'];
      $old_umask = umask(0);
      mkdir("upload/$kansio", 0777);
      
   
        $filename = basename($_FILES['uploaded_file']['name']);
        $ext = substr($filename, strrpos($filename, '.') + 1);
        if (($ext == "tif" ||$ext == "ps" || $ext == "eps" || $ext == "ai" || $ext == "sit" || $ext == "ZIP" || $ext == "zip" || $ext == "pdf") && ($_FILES["uploaded_file"]["type"] == "application/x-pdf" || $_FILES["uploaded_file"]["type"] == "application/acrobat" || $_FILES["uploaded_file"]["type"] == "applications/vnd.pdf" || $_FILES["uploaded_file"]["type"] == "text/pdf" || $_FILES["uploaded_file"]["type"] == "text/x-pdf" || $_FILES["uploaded_file"]["type"] == "image/tiff" || $_FILES["uploaded_file"]["type"] == "application/postscript" || $_FILES["uploaded_file"]["type"] == "application/x-stuffit" ||$_FILES["uploaded_file"]["type"] == "application/x-zip-compressed" ||$_FILES["uploaded_file"]["type"] == "application/pdf") && ($_FILES["uploaded_file"]["size"] ))
        {
            // Determine the path to which we want to save this file
// lLINE 18           $newname = dirname(__FILE__).'/upload/'$kansio;/.$_POST['sender'] .'_' . date('dmY') .'_' . $filename;
            // Check if the file with the same name is already exists on the server
            if (!file_exists($newname))
            {
                  // Attempt to move the uploaded file to it's new place
                  if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname)))
                  {
                   $newname = dirname(__FILE__).'/upload/'$kansio;/.$_POST['sender'] .'_' . date('dmY') .'_' . $filename;
                  echo "Tiedosto ".$_FILES["uploaded_file"]["name"]." on ladattu palvelimelle. ";
                  echo "<BR/>";echo "<BR/>";
                               
                  } else {
                        echo "Siirron aikana tapahtui virhe. Yritä uudestaan";
                        exit();
                        }
                    } else {
                         echo "Virhe! tiedosto ".$_FILES["uploaded_file"]["name"]." on palvelimella. Ole hyvä ja nimeä tiedosto uudestaan.";
                         exit();
                    }
        } else {
             echo "Virhe! Hyväksyttäviä tiedostomuotoja ovat: pdf, tiff, eps, ps, ai, sit sekä zip.";
             echo "<BR/>"; echo $ext;
             echo "<BR/>"; echo $filename;
             exit();
        }
} else {
echo "Image Uploaded: No";
echo "<BR/>";echo "<BR/>";
}
      
   
        $filename = basename($_FILES['uploaded_file']['name']);
        $ext = substr($filename, strrpos($filename, '.') + 1);
        if (($ext == "tif" ||$ext == "ps" || $ext == "eps" || $ext == "ai" || $ext == "sit" || $ext == "ZIP" || $ext == "zip" || $ext == "pdf") && ($_FILES["uploaded_file"]["type"] == "application/x-pdf" || $_FILES["uploaded_file"]["type"] == "application/acrobat" || $_FILES["uploaded_file"]["type"] == "applications/vnd.pdf" || $_FILES["uploaded_file"]["type"] == "text/pdf" || $_FILES["uploaded_file"]["type"] == "text/x-pdf" || $_FILES["uploaded_file"]["type"] == "image/tiff" || $_FILES["uploaded_file"]["type"] == "application/postscript" || $_FILES["uploaded_file"]["type"] == "application/x-stuffit" ||$_FILES["uploaded_file"]["type"] == "application/x-zip-compressed" ||$_FILES["uploaded_file"]["type"] == "application/pdf") && ($_FILES["uploaded_file"]["size"] ))
        {
            // Determine the path to which we want to save this file
           $newname = dirname(__FILE__).'/upload/'.$_POST['sender'] .'_' . date('dmY') .'_' . $filename;
            // Check if the file with the same name is already exists on the server
            if (!file_exists($newname))
            {
                  // Attempt to move the uploaded file to it's new place
                  if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname)))
                  {
                   $newname = dirname(__FILE__).'/upload/'.$_POST['sender'] .'_' . date('dmY') .'_' . $filename;
                  echo "Tiedosto ".$_FILES["uploaded_file"]["name"]." on ladattu palvelimelle. ";
                  echo "<BR/>";echo "<BR/>";
                               
                  } else {
                        echo "Siirron aikana tapahtui virhe. Yritä uudestaan";
                        exit();
                        }
                    } else {
                         echo "Virhe! tiedosto ".$_FILES["uploaded_file"]["name"]." on palvelimella. Ole hyvä ja nimeä tiedosto uudestaan.";
                         exit();
                    }
        } else {
             echo "Virhe! Hyväksyttäviä tiedostomuotoja ovat: pdf, tiff, eps, ps, ai, sit sekä zip.";
             echo "<BR/>"; echo $ext;
             echo "<BR/>"; echo $filename;
             exit();
        }
} else {
echo "Image Uploaded: No";
echo "<BR/>";echo "<BR/>";
}

Author

Commented:
Now i get next message:
Warning: move_uploaded_file(c:\inetpub\wwwroot/upload/.$kansio/james_31052007_edTIFF.tif) [function.move-uploaded-file]: failed to open stream: No such file or directory in c:\inetpub\wwwroot\uploader2.php on line 27

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\PHP\uploadtemp\php12E.tmp' to 'c:\inetpub\wwwroot/upload/.$kansio/james_31052007_edTIFF.tif' in
c:\inetpub\wwwroot\uploader2.php on line 27

I change these:
$newname = dirname(__FILE__).'/upload/.$kansio/'.$_POST['sender'] .'_' . date('dmY') .'_' . $filename;

Author

Commented:
can you help me?
Top Expert 2007
Commented:
Try to change the line to this:
$newname = dirname(__FILE__).'/upload/' .$kansio. '/'.$_POST['sender'] .'_' . date('dmY') .'_' . $filename;
Maybe than the destination file is valid (als long as the directory  dirname(__FILE__).'/upload/' .$kansio exists)

Author

Commented:
Thanks! It working!! Do you have any ideas how  to create pdf from textarea input?? I create another topic about that, thanks!! You get these points!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial