$_FILE upload code -- here's the modification

tgknight
2006-02-13
2013-05-30
  • tgknight

    tgknight - 2006-02-13

    In the method _prepare_post_body()

    The file upload portion needs to be modified to allow for uploads from a different filename... ie a file gets uploaded to my server and gets stored as a temp filename, but we want to upload it to the remote server with the same name as the user entered file.

    [code]
    reset($formfiles);
    while (list($field_name, $file_names) = each($formfiles)) {
        settype($file_names, "array");
        while (list($key, $file_name) = each($file_names)) {

            if ($key == 'name') {
                $realname = $file_name;
                continue;
            }

            if (!is_readable($file_name)) continue;

            $fp = fopen($file_name, "r");
            $file_content = fread($fp, filesize($file_name));
            fclose($fp);

            if ($key == 'tmp_name' && isset($realname)) {
                $base_name = basename($realname);
            } else {
                $base_name = basename($file_name);
            }

            $postdata .= "--".$this->_mime_boundary."\r\n";
            $postdata .= "Content-Disposition: form-data; name=\"$field_name\"; filename=\"$base_name\"\r\n\r\n";
            $postdata .= "$file_content\r\n";
        }
    }
    [/code]

     

    Related

    Code: code

    • tgknight

      tgknight - 2006-02-13

      Basically the addition takes into account the 'name' attribute for the $_FILE scope... and if it is set uses that as the filename to upload other than trying to search the server for a file that does not exist.

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks