Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10461
Modified Files:
NEWS serendipity_admin_images.inc.php
Log Message:
image manager can now upload a file to a specified filename. Fix conflicting
namespace of cookie/post variables.
Index: NEWS
===================================================================
RCS file: /cvsroot/php-blog/serendipity/NEWS,v
retrieving revision 1.93
retrieving revision 1.94
diff -u -d -r1.93 -r1.94
--- NEWS 21 Mar 2004 17:19:29 -0000 1.93
+++ NEWS 22 Mar 2004 15:19:25 -0000 1.94
@@ -3,6 +3,10 @@
Version 0.6 ()
------------------------------------------------------------------------
+ * Image upload: Can now specify alternate file name. Renamed
+ input field to not cause confusion with COOKIE-variable
+ (garvinhicking, isotopp)
+
* Image manager popup-window now resizable and with scrollbars
(garvinhicking)
Index: serendipity_admin_images.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_admin_images.inc.php,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- serendipity_admin_images.inc.php 22 Mar 2004 14:26:02 -0000 1.18
+++ serendipity_admin_images.inc.php 22 Mar 2004 15:19:25 -0000 1.19
@@ -96,38 +96,53 @@
<?php
// First find out whether to fetch a file or accept an upload
- $checkfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . basename($serendipity['POST']['url']);
- if ($serendipity['POST']['url'] != '' && $serendipity['POST']['url'] != 'http://') {
- if (file_exists($checkfile)) {
- echo ERROR_FILE_EXISTS_ALREADY;
+ if ($serendipity['POST']['imageurl'] != '' && $serendipity['POST']['imageurl'] != 'http://') {
+ if (!empty($serendipity['POST']['target_filename'])) {
+ $tfile = $serendipity['POST']['target_filename'];
+ } else {
+ $tfile = basename($serendipity['POST']['imageurl']);
+ }
+
+ $target = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $tfile;
+
+ if (file_exists($target)) {
+ echo '(' . $target . ') ' . ERROR_FILE_EXISTS_ALREADY;
} else {
// Fetch file
- if (!$fContent = @file_get_contents($serendipity['POST']['url']) ) {
- printf(REMOTE_FILE_NOT_FOUND, $serendipity['POST']['url']);
+ if (!$fContent = @file_get_contents($serendipity['POST']['imageurl']) ) {
+ printf(REMOTE_FILE_NOT_FOUND, $serendipity['POST']['imageurl']);
} else {
- $fp = fopen($checkfile, 'w');
+ $fp = fopen($target, 'w');
fwrite($fp, $fContent);
fclose($fp);
- printf(FILE_FETCHED . '<br />', $serendipity['POST']['url']);
+ printf(FILE_FETCHED . '<br />', $serendipity['POST']['imageurl'], $tfile);
// Create thumbnail
- serendipity_makeThumbnail(basename($serendipity['POST']['url']));
+ serendipity_makeThumbnail($tfile);
echo THUMB_CREATED_DONE . '<br />';
}
}
} else {
- if (file_exists($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $_FILES['userfile']['name'])) {
- echo ERROR_FILE_EXISTS_ALREADY;
+ if (!empty($serendipity['POST']['target_filename'])) {
+ $tfile = $serendipity['POST']['target_filename'];
+ } else {
+ $tfile = $_FILES['userfile']['name'];
+ }
+
+ $target = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $tfile;
+
+ if (file_exists($target)) {
+ echo '(' . $target . ') ' . ERROR_FILE_EXISTS_ALREADY;
} else {
// Accept file
- if (move_uploaded_file($_FILES['userfile']['tmp_name'], $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $_FILES['userfile']['name'])) {
- printf(FILE_UPLOADED . '<br />', $_FILES['userfile']['name']);
+ if (move_uploaded_file($_FILES['userfile']['tmp_name'], $target)) {
+ printf(FILE_UPLOADED . '<br />', $_FILES['userfile']['name'], $target);
@umask(0000);
- @chmod($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $_FILES['userfile']['name'], 0664);
+ @chmod($target, 0664);
// Create thumbnail
- serendipity_makeThumbnail($_FILES['userfile']['name']);
+ serendipity_makeThumbnail($tfile);
echo THUMB_CREATED_DONE . '<br />';
} else {
echo ERROR_UNKNOWN_NOUPLOAD . '<br />';
@@ -140,7 +155,14 @@
?>
<?php echo ADD_IMAGE_BLAHBLAH; ?>
- <form action="?" method="POST" enctype="multipart/form-data">
+ <script type="text/javascript">
+ function getfilename(field, value) {
+ re = /^.+[\/\\]+?(.+)$/;
+ document.getElementById(field).value = value.replace(re, "$1");
+ }
+ </script>
+
+ <form action="?" method="POST" id="uploadform" enctype="multipart/form-data">
<div>
<input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
<input type="hidden" name="serendipity[action]" value="admin" />
@@ -150,7 +172,7 @@
<table>
<tr>
<td nowrap="nowrap"><?php echo ENTER_IMAGE_URL; ?></td>
- <td><input type="text" name="serendipity[url]" value="" size="40" /></td>
+ <td><input type="text" name="serendipity[imageurl]" onblur="getfilename('target_filename', this.value);" onchange="getfilename('target_filename', this.value);" onkeyup="getfilename('target_filename', this.value);" value="" size="40" /></td>
</tr>
<tr>
@@ -159,7 +181,16 @@
<tr>
<td nowrap='nowrap'><?php echo ENTER_IMAGE_TO_UP; ?></td>
- <td><input name="userfile" type="file"/></td>
+ <td><input name="userfile" onchange="getfilename('target_filename', this.value);" onblur="getfilename('target_filename', this.value);" onkeyup="getfilename('target_filename', this.value);" type="file" /></td>
+ </tr>
+
+ <tr>
+ <td align="center" colspan="2"><br /></td>
+ </tr>
+
+ <tr>
+ <td nowrap='nowrap'><?php echo IMAGE_NAME; ?></td>
+ <td><input type="text" id="target_filename" name="serendipity[target_filename]" value="" size="40" /></td>
</tr>
<tr>
|