From 932fe3d45ee14b9de5f3b52616dcb282cddcf2af Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Wed, 19 Mar 2003 20:23:17 +0000 Subject: [PATCH] Blob upload via pre-uploaded (FTP) files in $cfg['UploadDir']. --- ChangeLog | 6 +++++ tbl_change.php3 | 26 +++++++++++++++++++++ tbl_query_box.php3 | 34 +++++++++++++++++++++++++++ tbl_replace_fields.php3 | 52 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+) diff --git a/ChangeLog b/ChangeLog index 51928115f..6ba2d9fb5 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,12 @@ phpMyAdmin - Changelog $Id$ $Source$ +2003-03-19 Garvin Hicking + * tbl_change.php3, tbl_query_box.php3, tbl_replace_fields.php3: + Display select box for stored files on Server ($cfg['UploadDir']) in every SQL + input area (SQL window, table properties) AND in the 'Insert/Update field' display + where you can upload files to blob fields. Experimental. + 2003-03-19 Alexander M. Turek * lang/german-*.inc.php3: Updates. diff --git a/tbl_change.php3 b/tbl_change.php3 index 2d1d8c9d7..b88589858 100755 --- a/tbl_change.php3 +++ b/tbl_change.php3 @@ -611,6 +611,32 @@ for ($i = 0; $i < $fields_cnt; $i++) { if ($is_upload && $is_blob) { echo ''; } + + if ($cfg['UploadDir'] != '') { + if ($handle = @opendir($cfg['UploadDir'])) { + $is_first = 0; + while ($file = @readdir($handle)) { + if (is_file($cfg['UploadDir'] . $file) && substr($file, -4) != '.sql') { + if ($is_first == 0) { + echo "
\n"; + echo ' ' . $strOr . '' . ' ' . $strWebServerUploadDirectory . ' :
' . "\n"; + echo ' ' . "\n"; + } // end if (isfirst > 0) + @closedir($handle); + } else { + echo ' ' . $strError . '
' . "\n"; + echo ' ' . $strWebServerUploadDirectoryError . "\n"; + } + } // end if (web-server upload directory) + echo ''; } // end else if ( binary or blob) diff --git a/tbl_query_box.php3 b/tbl_query_box.php3 index 6ff4c2013..6279b22c0 100755 --- a/tbl_query_box.php3 +++ b/tbl_query_box.php3 @@ -175,6 +175,40 @@ if ($is_upload && (!isset($is_inside_querywindow) || } // end if echo "\n"; +// web-server upload directory +// (TODO: display the charset selection, even if is_upload == FALSE) +if ($cfg['UploadDir'] != '' && !isset($is_inside_querywindow) || + ($cfg['UploadDir'] != '' && isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' || $querydisplay_tab == 'full'))) { + + if ($handle = @opendir($cfg['UploadDir'])) { + $is_first = 0; + while ($file = @readdir($handle)) { + if (is_file($cfg['UploadDir'] . $file) && substr($file, -4) == '.sql') { + if ($is_first == 0) { + echo "\n"; + echo ' ' . ((isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && $querydisplay_tab == 'full') || !isset($is_inside_querywindow) ? '' . $strOr . '' : '') . ' ' . $strWebServerUploadDirectory . ' :
' . "\n"; + echo '
' . "\n"; + echo ' ' . "\n" + . '
' . "\n\n"; + } // end if (isfirst > 0) + @closedir($handle); + } else { + echo '
' . "\n"; + echo ' ' . $strError . '
' . "\n"; + echo ' ' . $strWebServerUploadDirectoryError . "\n"; + echo '
' . "\n"; + } +} // end if (web-server upload directory) +echo "\n"; + // Encoding setting form appended by Y.Kawada if (function_exists('PMA_set_enc_form')) { echo PMA_set_enc_form(' '); diff --git a/tbl_replace_fields.php3 b/tbl_replace_fields.php3 index 75d4a0c52..b4b6a6e7e 100755 --- a/tbl_replace_fields.php3 +++ b/tbl_replace_fields.php3 @@ -49,6 +49,58 @@ if (isset(${"fields_upload_" . $key}) && ${"fields_upload_" . $key} != 'none'){ // void } + } elseif (!empty(${'fields_uploadlocal_' . $key})) { + $file_to_upload = $cfg['UploadDir'] . eregi_replace('\.\.*', '.', ${'fields_uploadlocal_' . $key}); + + // A local file will be uploaded. + $open_basedir = ''; + if (PMA_PHP_INT_VERSION >= 40000) { + $open_basedir = @ini_get('open_basedir'); + } + if (empty($open_basedir)) { + $open_basedir = @get_cfg_var('open_basedir'); + } + + // If we are on a server with open_basedir, we must move the file + // before opening it. The doc explains how to create the "./tmp" + // directory + + $unlink = false; + if (!empty($open_basedir)) { + + $tmp_subdir = (PMA_IS_WINDOWS ? '.\\tmp\\' : './tmp/'); + + // function is_writeable() is valid on PHP3 and 4 + if (!is_writeable($tmp_subdir)) { + // if we cannot move the file don't change blob fields + $file_to_upload = ''; + } else { + $new_file_to_upload = $tmp_subdir . basename($file_to_upload); + if (PMA_PHP_INT_VERSION < 40003) { + copy($file_to_upload, $new_file_to_upload); + } else { + move_uploaded_file($file_to_upload, $new_file_to_upload); + } + + $file_to_upload = $new_file_to_upload; + $unlink = true; + } + } + + if ($file_to_upload != '') { + + $val = fread(fopen($file_to_upload, "rb"), filesize($file_to_upload)); + if (!empty($val)) { + $val = '0x' . bin2hex($val); + $seen_binary = TRUE; + $check_stop = TRUE; + } + + if ($unlink == TRUE) { + unlink($file_to_upload); + } + } + } // garvin: else: Post-field contains no data. Blob-fields are preserved, see below. ($protected$)