Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1:/tmp/cvs-serv18117
Modified Files:
serendipity_admin_images.inc.php
Log Message:
Added lots of error-handling and minor tweaks
Index: serendipity_admin_images.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_admin_images.inc.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- serendipity_admin_images.inc.php 18 May 2003 20:52:20 -0000 1.4
+++ serendipity_admin_images.inc.php 22 May 2003 23:19:33 -0000 1.5
@@ -87,12 +87,18 @@
break;
case "DoDelete":
+ $fThumb = serendipity_parseFileName($serendipity["fname"]);
+ $fThumb = $fThumb[0].".".$serendipity["thumbSuffix"].".".$fThumb[1];
if ( file_exists($serendipity["serendipityPath"].$serendipity["uploadPath"].$serendipity["fname"]) ) {
if ( @unlink($serendipity["serendipityPath"].$serendipity["uploadPath"].$serendipity["fname"]) ) {
echo "Deleted the image entitled <b>". $serendipity['fname'] ."</b>";
} else {
echo "Unable to delete <b>". $serendipity['fname'] ."</b>";
}
+ if ( @unlink($serendipity["serendipityPath"].$serendipity["uploadPath"].$fThumb) ) {
+ echo "<br>Deleted the thumbnail entitled <b>". $fThumb ."</b>";
+ }
+
} else {
echo "I was unable to locate the file entitled <b>". $serendipity['fname'] ."</b>, maybe it has already been deleted?";
}
@@ -147,42 +153,41 @@
case "add":
echo "<b>".ADDING_IMAGE."</b><p>";
// First find out whether to fetch a file or accept an upload
- if ($serendipity["POST"]["url"] != "http://") {
- if (file_exists($serendipity["serendipityPath"].$serendipity["uploadPath"].
- basename($serendipity["POST"]["url"]))) {
- echo "Error: File already exists on your machine!";
- }
+ if ($serendipity["POST"]["url"] != "" && $serendipity["POST"]["url"] != "http://") {
+ if (file_exists($serendipity["serendipityPath"].$serendipity["uploadPath"].basename($serendipity["POST"]["url"]))) {
+ echo ERROR_FILE_EXISTS_ALREADY;
+ }
else {
// Fetch file
- $fp = fopen($serendipity["serendipityPath"].$serendipity["uploadPath"].basename($serendipity["POST"]["url"]), "w");
- fwrite($fp, file_get_contents($serendipity["POST"]["url"]));
- fclose($fp);
- echo $serendipity["POST"]["url"]." fetched!<br>";
+ if ( !$fContent = @file_get_contents($serendipity["POST"]["url"]) ) {
+ echo "File was not located on the remote server, are you sure the URL: <b>". $serendipity["POST"]["url"] ."</b> is correct?";
+ } else {
+ $fp = fopen($serendipity["serendipityPath"].$serendipity["uploadPath"].basename($serendipity["POST"]["url"]), "w");
+ fwrite($fp, $fContent);
+ fclose($fp);
+
+ echo $serendipity["POST"]["url"]." fetched!<br>";
- // Create thumbnail
- serendipity_makeThumbnail(basename($serendipity["POST"]["url"]));
- echo THUMB_CREATED_DONE;
- }
- }
- else {
- if (file_exists($serendipity["serendipityPath"].$serendipity["uploadPath"].
- $_FILES['userfile']['name'])) {
- echo ERROR_FILE_EXISTS_ALREADY;
- }
- else {
- // Accept file
- if (move_uploaded_file($_FILES['userfile']['tmp_name'],
- $serendipity["serendipityPath"].$serendipity["uploadPath"].$_FILES['userfile']['name'])) {
- echo $_FILES['userfile']['name']." successfully uploaded!<br>";
+ // Create thumbnail
+ serendipity_makeThumbnail(basename($serendipity["POST"]["url"]));
+ echo THUMB_CREATED_DONE;
+ }
+ }
+ } else {
+ if (file_exists($serendipity["serendipityPath"].$serendipity["uploadPath"].$_FILES['userfile']['name'])) {
+ echo ERROR_FILE_EXISTS_ALREADY;
+ } else {
+ // Accept file
+ if (move_uploaded_file($_FILES['userfile']['tmp_name'],$serendipity["serendipityPath"].$serendipity["uploadPath"].$_FILES['userfile']['name'])) {
+ echo $_FILES['userfile']['name']." successfully uploaded!<br>";
- // Create thumbnail
- serendipity_makeThumbnail($_FILES['userfile']['name']);
- echo THUMB_CREATED_DONE;
- }
- else {
- echo ERROR_UNKNOWN_NOUPLOAD;
- }
- }
+ // Create thumbnail
+ serendipity_makeThumbnail($_FILES['userfile']['name']);
+ echo THUMB_CREATED_DONE;
+ } else {
+ echo ERROR_UNKNOWN_NOUPLOAD;
+ }
+ }
}
// Create thumbnail
@@ -201,7 +206,7 @@
<input type="hidden" name="serendipity[adminAction]" value="add">
<tr>
<td nowrap='nowrap'><?=ENTER_IMAGE_URL?></td>
- <td><input type="text" name="serendipity[url]" value="http://" size="40"></td>
+ <td><input type="text" name="serendipity[url]" value="" size="40"></td>
</tr>
<tr><td align="center" colspan="2"><b>Or</b></td></tr>
<tr>
|