Skip to main content
Known Participant
November 14, 2009
Answered

Only getting base file name, not full file path in file upload form

  • November 14, 2009
  • 1 reply
  • 752 views

I cannot seem to get the full file path in the following html code that I need for my php script to ftp a video file.  I show the method of retrieving the file info in php first.  My ftp_nb_fput is not working because it cannot find the file as it assumes it is on the server, not the local machine.  I am using this so that I can see the progress of the upload without too much code:

ANY HELP WOULD BE GREATLY APPRECIATED !

<?php

    $source_file = isset($_POST['filen']) ? ($_POST['filen']):($_SESSION['filen']);

'

'

        $fp = fopen($source_file, 'r');

        $ret = ftp_nb_fput($conn_id, $destination_file, $fp, FTP_BINARY);
        while ($ret == FTP_MOREDATA)
              {
               $uploaded = 100 * ftell($fh) / $file_size;
               print "$uploaded % complete \n";
// Continue upload...
            $ret = ftp_nb_continue($conn_id);
               }
         if ($ret != FTP_FINISHED)
         {  include 'upload_video_failed.htm';
            exit(1);}
         else   {include 'upload_video_db.php';}
         fclose($fp);

'

'

?>

    <FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="./upload_video.php">

      <TABLE>
        <TR>
          <TD> Video<span class="style1"> *</span></TD>
          <TD><INPUT NAME="filen" id="filen" TYPE="file" size="30" class="fields"></TD>
        </TR>
        <TR>
          <TD> Title<span class="style1"> *</span></TD>
          <TD><INPUT NAME="title" id="title" TYPE="text" size="43" class="fields"></TD>
        </TR>
        <TR>
          <TD> Category<span class="style1"> *</span></TD>
      <TD><select name="category" id="category" class="h1">
              <option selected>Select the category that best describes your video</option>
          <option>Documentary</option>
          <option>Educational</option>
              <option>Interesting Facts</option>
    </select>
            </TD>
        </TR>
        <TR VALIGN="top">
          <TD>Description</TD>
          <TD><TEXTAREA NAME="description" id="description" cols="32" ROWS="2" WRAP class="h1"></TEXTAREA></TD>
        </TR>
        <TR>
          <TD> Duration<span class="style1"></span></TD>
      <TD><select name="duration" id="duration" class="h1">
              <option>1 Day</option>
          <option>1 Week</option>
              <option>1 Month</option>
              <option>3 Months</option>
              <option>6 Months</option>
          <option>1 Year</option>
              <option selected>Until Removed</option></select>
            </TD>
        </TR>
        <TR>
          <TD> Tags<span class="style1"></span></TD>
          <TD><INPUT NAME="tags" id="tags" TYPE="text" size="43" class="fields"></TD>
        </TR>
        <TR>
          <TD></TD>
          <TD><INPUT name="Submit" TYPE="Submit" VALUE="Upload"></TD>
        </TR>
      </TABLE>
    </FORM>

This topic has been closed for replies.
Correct answer David_Powers

marcusinfla wrote:

ONLY PROBLEM IS THAT I CANNOT SEEM TO UPLOAD ANY VIDEOS LARGER THAN 4 MB.  I included the attribute MAXLENGTH = 100000000 (100 Mb) and this does not help.

ANY IDEAS ?

A good idea is to read the PHP manual. As the following page explains, the maximum size of uploads is controlled by PHP configuration directives: http://docs.php.net/manual/en/features.file-upload.common-pitfalls.php. Normally, the maximum size for an individual file is 2MB and the total maximum is 8MB. If you're on shared hosting, I doubt if the hosting company will be willing to change the configuration directives to permit 100MB uploads, but you can always ask.

1 reply

David_Powers
Inspiring
November 15, 2009

marcusinfla wrote:

I cannot seem to get the full file path in the following html code that I need for my php script to ftp a video file.

When submitting a file through a form, the file is uploaded automatically, and its details are in the $_FILES array, not the $_POST array.

if ($_POST && $_FILES['filen']['error'] === 0) {

  if (is_uploaded_file($_FILES['filen']['tmp_name'])) {

    $file = $_FILES['filen']['tmp_name'];

    // do something with the file

  }

}

See http://docs.php.net/manual/en/features.file-upload.php.

Known Participant
November 15, 2009

Thanks for the help David, I really appreciate you taking the time.

Quick question, before I do anything with the file, where is the file temporary uploaded to?  Is it in the same directory as the web page, temporary folder or in memory ?   Or is it just a 'handle' ?  I assume I still have to ftp_put() it so that I can store it in a destination folder on my ftp server ?

The reason I ask this is because even when I implemented your suggestion it is still givinng me the following error:

ftp_put(): Rename/move failure: No such file or directory in /home/content/i/n/c/..../html/upload_video.php  (the php script file I am using for the ftp upload).  I think PHP assumes my source file is on the remote server already.

Also, in dealing with mid to large video files (50 - 100 Mb), would this be a problem in terms of memory ?

Excuse my ignornace but obviously it is the first time I'm doing this.

Thanks,

Marcus