Hi everyone,
The other day I started a thread asking for help to upload a pdf file and DeadlySin3 sent me the following http://deadlysinx.net/FREE/UPLOAD/ , so I started playing with it and I finally made it work with my settings, but my only problem is that I am not uploading the .pdf file, just an strange file name called phpWvp8gy and this is the message I receive:
name: myfilename.pdf
type: application/pdf
tmp_name: /tmp/phpWvp8gy
error: 0
size: 296351

Can anyone please help me solve this issue?

Here are the codes:

include("vars.php");
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

foreach( $_FILES as $file_name => $file_array ) 
{
echo "name: ".$file_array['name']."<br />\n";
echo "type: ".$file_array['type']."<br />\n";
echo "tmp_name: ".$file_array['tmp_name']."<br />\n";
echo "error: ".$file_array['error']."<br />\n";
echo "size: ".$file_array['size']."<br />\n";
// print_r($_FILES);

$tmp_name = $file_array['tmp_name'];

if( strstr( $tmp_name, "/tmp/" ) ) {
    $tmp_name = str_replace("/tmp/", "", $tmp_name); # strip location from name
}

foreach ( $allowedExts as $acceptThis ) {
if(is_uploaded_file( $file_array['tmp_name'] ) && $file_array['type'] == "application/$acceptThis" ) {

$size=$file_array['size'];
if($size > $maxSize)
{
exit("The pdf file is too large in size.");
}

move_uploaded_file( $file_array['tmp_name'], "$file_dir/".$tmp_name)
or die("Couldn't Copy");
echo "<img src=\"$file_url/".$tmp_name."\">";
echo "<br />\n\n";

} // End Foreach loop 2

} // End IF statement

} // End Foreach loop 1

This is the Form where I call the file:

<form action="<?php echo "$self"; ?>" enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo "$maxSize"; ?>">
<input type="file" name="fupload">
<input type="submit" value="Upload">
<br />
</form>

This is the other file named vars.php

# vars.php
/*
 *  Maximum Size an image may be
 *
 *  $maxImageSize
 *
 *  51200 = 50 KB
 *  512000 = 500 KB
 *
 */

$maxSize = "512000";

/*
 *  Path Information
 *
 *  1.) $file_dir
 *
 *  2.)$file_url
 *
 *  1.) full path ex /home/user/public_html/images
 *
 *  2.) full url ex http://www.site.com/images
 *
 *  NO TRAILING SLASH!!
 * Directory to move images to should be chmod 777
 *
 */

$file_dir = "pdffolder/";
$file_url = "http://www.mywebsite.com/pdffolder/";

/*
 *  Defining accepted Image Types
 *
 *  Add more like shown below: 
 *
 *  $acceptedImageType[] = "type";
 *
 */

$allowedExts = array("pdf");
$allowedFileType[] = "application/pdf";

/*
 *  Defining a Page's Own URL
 *
 *  $self=$_SERVER['PHP_SELF'];
 *
 */

$self=$_SERVER['PHP_SELF'];

    Your call to [man]move_uploaded_file/man shows that the destination file name references the "tmp_name" item rather than the "name" item.

      Hi bradgrafelman and thanks for replying,
      I have changed the item to "name", but now I receive the message "Couldn't Copy".
      This is how it looks now:

      move_uploaded_file( $file_array['name'], "$file_dir/".$name) 
      or die("Couldn't Copy"); 
      echo "<img src=\"$file_url/".$name."\">"; 
      echo "<br />\n\n";

        Because now you're trying to move a file that (shouldn't) exist.

        bradgrafelman pointed out that it was your destination file name that was wrong. You didn't need to change the source file name as well.

        That's why [font=monospace]$file_array[/font] has both names.

          12 days later

          Hi Weedpacket,
          I think I have changed everything to the way it was, but now I receive a message saying "No file Chosen".
          Can you please point me where exactly is my error?

          include("vars.php");
          // In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
          // of $_FILES.
          
          foreach( $_FILES as $file_name => $file_array ) 
          {
          echo "name: ".$file_array['name']."<br />\n";
          echo "type: ".$file_array['type']."<br />\n";
          echo "tmp_name: ".$file_array['tmp_name']."<br />\n";
          echo "error: ".$file_array['error']."<br />\n";
          echo "size: ".$file_array['size']."<br />\n";
          // print_r($_FILES);
          
          $tmp_name = $file_array['tmp_name'];
          
          if( strstr( $tmp_name, "/tmp/" ) ) {
              $tmp_name = str_replace("/tmp/", "", $tmp_name); # strip location from name
          }
          
          foreach ( $allowedFileType as $acceptThis ) {
          if(is_uploaded_file( $file_array['tmp_name'] ) && $file_array['type'] == "application/$acceptThis" ) {
          
          $size=$file_array['size'];
          if($size > $maxImageSize)
          {
          exit("The image is too large in size.");
          }
          
          move_uploaded_file( $file_array['name'], "$file_dir/".$name)
          or die("Couldn't Copy");
          echo "<img src=\"$file_url/".$name."\">";
          echo "<br />\n\n";
          
          } // End Foreach loop 2
          
          } // End IF statement
          
          } // End Foreach loop 1
          <form action="<?php echo "$self"; ?>" enctype="multipart/form-data" method="POST">
          <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo "$maxSize"; ?>">
          <input type="file" name="fupload">
          <input type="submit" value="Upload">
          <br />
          </form>
          # vars.php 
          /* 
           *  Maximum Size an image may be 
           * 
           *  $maxImageSize 
           * 
           *  51200 = 50 KB 
           *  512000 = 500 KB 
           * 
           */ 
          
          $maxImageSize = "512000"; 
          
          /* 
           *  Path Information 
           * 
           *  1.) $file_dir 
           * 
           *  2.)$file_url 
           * 
           *  1.) full path ex /home/user/public_html/images 
           * 
           *  2.) full url ex http://www.site.com/images 
           * 
           *  NO TRAILING SLASH!! 
           * Directory to move images to should be chmod 777 
           * 
           */ 
          
          $file_dir = "/download/"; 
          $file_url = "http://www.mywebsite.com/download/"; 
          
          /* 
           *  Defining accepted Image Types 
           * 
           *  Add more like shown below:  
          * * $acceptedImageType[] = "type"; * */ $allowedExts = array("pdf"); //$acceptedImageType[] = "application/pdf"; $allowedFileType[] = "application/pdf"; /* * Defining a Page's Own URL * * $self=$_SERVER['PHP_SELF']; * */ $self=$_SERVER['PHP_SELF'];

            Hi Weedpacket,
            Believe it or not I made it work by just putting message to the program to know where the value was coming from, but when I move both programs to a subfolder, then it stops working. It only works when I have it in the root of the website.
            I have move both files to a subfolder named pdf which is inside of a folder named pdffiles and the folder where I want to upload the file is located in my root folder and the name of that folder is uploaded_files.
            Here are the programs in case anyone can help me fix the root in each program. Thanks in advance!!:

            include('var.php')
            // In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
            // of $_FILES.
            
            foreach( $_FILES as $file_name => $file_array ) 
            {
            echo "name: ".$file_array['name']."<br />\n";
            echo "type: ".$file_array['type']."<br />\n";
            echo "tmp_name: ".$file_array['tmp_name']."<br />\n";
            echo "error: ".$file_array['error']."<br />\n";
            echo "size: ".$file_array['size']."<br />\n";
            // print_r($_FILES);
            
            $nombre_archivo = $file_array['name'];
            
            if( strstr( $nombre_archivo, "/tmp/" ) ) {
                $nombre_archivo = str_replace("/tmp/", "", $nombre_archivo); # strip location from name
            
            }
            
            foreach ( $acceptedFileType as $acceptThis ) {
            if(is_uploaded_file( $file_array['tmp_name'] ) && $file_array['type'] == "application/$acceptThis" ) {
            
            $size=$file_array['size'];
            if($size > $maxImageSize)
            {
            exit("The image is too large in size.");
            }
            
            move_uploaded_file( $file_array['tmp_name'], "$file_dir/".$nombre_archivo)
            or die("Couldn't Copy");
            //echo "<img src=\"$file_url/".$nombre_archivo."\">"; I removed this part because I'm not uploading images right now.
            echo "<br />\n\n";
            
            } // End Foreach loop 2
            
            } // End IF statement
            
            } // End Foreach loop 1
            <form action="<?php echo "$self"; ?>" enctype="multipart/form-data" method="POST">
            <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo "$maxImageSize"; ?>">
            <input type="file" name="fupload">
            <input type="submit" value="Upload">
            # var.php
            /*
             *  Maximum Size a file may be
             *
             *  $maxImageSize
             *
             *  51200 = 50 KB
             *  512000 = 500 KB
             *
             */
            
            $maxImageSize = "350000"; 
            
            
            
            /*
             *  Path Information
             *
             *  1.) $file_dir
             *
             *  2.)$file_url
             *
             *  1.) full path ex /home/user/public_html/images
             *
             *  2.) full url ex http://www.site.com/images
             *
             *  NO TRAILING SLASH!!
             * Directory to move images to should be chmod 777
             *
             */
            
            $file_dir = "uploaded_files/";
            $file_url = "http://www.mywebsite.com/uploaded_files";
            
            /*
             *  Defining accepted Image Types
             *
             *  Add more like shown below: 
             *
             *  $acceptedImageType[] = "type";
             *
             */
            
            
            $acceptedFileType = array ( "pdf" );
            $acceptedFileType[] = "application/pdf";
            
            /*
             *  Defining a Page's Own URL
             *
             *  $self=$_SERVER['PHP_SELF'];
             *
             */
            
            $self=$_SERVER['PHP_SELF'];
              Write a Reply...