2003-05-22 08:12:53 -04:00
< ? php
2004-10-21 11:16:03 -04:00
require_once ( 'admin.php' );
2004-04-23 02:46:53 -04:00
2004-02-05 09:28:02 -05:00
$title = 'Upload Image or File' ;
2003-05-22 08:12:53 -04:00
2004-02-05 09:28:02 -05:00
require_once ( 'admin-header.php' );
2003-05-22 08:12:53 -04:00
if ( $user_level == 0 ) //Checks to see if user has logged in
2004-04-23 02:46:53 -04:00
die ( __ ( " Cheatin' uh ? " ));
2003-05-22 08:12:53 -04:00
2004-03-01 01:13:32 -05:00
if ( ! get_settings ( 'use_fileupload' )) //Checks if file upload is enabled in the config
2004-04-23 02:46:53 -04:00
die ( __ ( " The admin disabled this function " ));
2003-05-22 08:12:53 -04:00
2004-04-12 13:25:59 -04:00
$allowed_types = explode ( ' ' , trim ( strtolower ( get_settings ( 'fileupload_allowedtypes' ))));
2003-10-17 15:26:05 -04:00
2004-04-20 18:56:47 -04:00
if ( $_POST [ 'submit' ]) {
2004-02-05 09:28:02 -05:00
$action = 'upload' ;
} else {
$action = '' ;
2003-05-22 08:12:53 -04:00
}
2004-03-01 01:13:32 -05:00
if ( ! is_writable ( get_settings ( 'fileupload_realpath' )))
2004-02-05 09:28:02 -05:00
$action = 'not-writable' ;
2003-10-17 15:26:05 -04:00
?>
2003-05-22 08:12:53 -04:00
2004-02-05 09:28:02 -05:00
< div class = " wrap " >
2003-05-22 08:12:53 -04:00
2004-02-05 09:28:02 -05:00
< ? php
switch ( $action ) {
case 'not-writable' :
2003-05-22 08:12:53 -04:00
?>
2004-04-23 02:46:53 -04:00
< p >< ? php printf ( __ ( " It doesn't look like you can use the file upload feature at this time because the directory you have specified (<code>%s</code>) doesn't appear to be writable by WordPress. Check the permissions on the directory and for typos. " ), get_settings ( 'fileupload_realpath' )) ?> </p>
2003-05-22 08:12:53 -04:00
2004-02-05 09:28:02 -05:00
< ? php
break ;
case '' :
foreach ( $allowed_types as $type ) {
$type_tags [] = " <code> $type </code> " ;
}
$i = implode ( ', ' , $type_tags );
?>
2004-04-23 20:16:27 -04:00
< p >< ? php printf ( __ ( 'You can upload files with the extension %1$s as long as they are no larger than %2$s <abbr title="Kilobytes">KB</abbr>. If you’re an admin you can configure these values under <a href="%3$s">options</a>.' ), $i , get_settings ( 'fileupload_maxk' ), 'options-misc.php' ) ?> </p>
2004-02-05 09:28:02 -05:00
< form action = " upload.php " method = " post " enctype = " multipart/form-data " >
< p >
2004-04-23 02:46:53 -04:00
< label for = " img1 " >< ? php _e ( 'File:' ) ?> </label>
2004-02-05 09:28:02 -05:00
< br />
2004-03-01 01:13:32 -05:00
< input type = " hidden " name = " MAX_FILE_SIZE " value = " <?php echo get_settings('fileupload_maxk') * 1024 ?> " />
2004-02-05 09:28:02 -05:00
< input type = " file " name = " img1 " id = " img1 " size = " 35 " class = " uploadform " /></ p >
< p >
2004-04-23 02:46:53 -04:00
< label for = " imgdesc " >< ? php _e ( 'Description:' ) ?> </label><br />
2004-02-05 09:28:02 -05:00
< input type = " text " name = " imgdesc " id = " imgdesc " size = " 30 " class = " uploadform " />
</ p >
2004-04-23 02:46:53 -04:00
< p >< ? php _e ( 'Create a thumbnail?' ) ?> </p>
2004-02-05 09:28:02 -05:00
< p >
< label for = " thumbsize_no " >
< input type = " radio " name = " thumbsize " value = " none " checked = " checked " id = " thumbsize_no " />
2004-04-23 02:46:53 -04:00
< ? php _e ( 'No thanks' ) ?> </label>
2004-02-05 09:28:02 -05:00
< br />
< label for = " thumbsize_small " >
< input type = " radio " name = " thumbsize " value = " small " id = " thumbsize_small " />
2004-04-23 02:46:53 -04:00
< ? php _e ( 'Small (200px largest side)' ) ?> </label>
2004-02-05 09:28:02 -05:00
< br />
< label for = " thumbsize_large " >
< input type = " radio " name = " thumbsize " value = " large " id = " thumbsize_large " />
2004-04-23 02:46:53 -04:00
< ? php _e ( 'Large (400px largest side)' ) ?> </label>
2004-02-05 09:28:02 -05:00
< br />
< label for = " thumbsize_custom " >
< input type = " radio " name = " thumbsize " value = " custom " id = " thumbsize_custom " />
2004-04-23 02:46:53 -04:00
< ? php _e ( 'Custom size' ) ?> </label>
2004-02-05 09:28:02 -05:00
:
< input type = " text " name = " imgthumbsizecustom " size = " 4 " />
2004-04-23 02:46:53 -04:00
< ? php _e ( 'px (largest side)' ) ?> </p>
< p >< input type = " submit " name = " submit " value = " <?php _e('Upload File') ?> " /></ p >
2004-02-05 09:28:02 -05:00
</ form >
</ div >< ? php
break ;
case 'upload' :
2003-05-22 08:12:53 -04:00
2004-10-08 10:59:52 -04:00
//Makes sure they choose a file
2003-05-22 08:12:53 -04:00
2004-10-01 20:46:30 -04:00
//print_r($_FILES);
2003-05-22 08:12:53 -04:00
//die();
2004-10-01 20:46:30 -04:00
$imgalt = basename ( ( isset ( $_POST [ 'imgalt' ])) ? $_POST [ 'imgalt' ] : '' );
2004-10-08 10:59:52 -04:00
2004-10-01 20:46:30 -04:00
$img1_name = ( strlen ( $imgalt )) ? $imgalt : basename ( $_FILES [ 'img1' ][ 'name' ] );
$img1_type = ( strlen ( $imgalt )) ? $_POST [ 'img1_type' ] : $_FILES [ 'img1' ][ 'type' ];
$imgdesc = htmlentities2 ( $imgdesc );
2004-02-05 09:28:02 -05:00
$imgtype = explode ( " . " , $img1_name );
2004-04-12 13:25:59 -04:00
$imgtype = strtolower ( $imgtype [ count ( $imgtype ) - 1 ]);
2004-02-05 09:28:02 -05:00
if ( in_array ( $imgtype , $allowed_types ) == false ) {
2004-04-23 20:16:27 -04:00
die ( sprintf ( __ ( 'File %1$s of type %2$s is not allowed.' ) , $img1_name , $imgtype ));
2004-02-05 09:28:02 -05:00
}
if ( strlen ( $imgalt )) {
2004-03-01 01:13:32 -05:00
$pathtofile = get_settings ( 'fileupload_realpath' ) . " / " . $imgalt ;
2004-10-08 10:59:52 -04:00
$img1 = $_POST [ 'img1' ];
2004-02-05 09:28:02 -05:00
} else {
2004-03-01 01:13:32 -05:00
$pathtofile = get_settings ( 'fileupload_realpath' ) . " / " . $img1_name ;
2004-10-01 20:46:30 -04:00
$img1 = $_FILES [ 'img1' ][ 'tmp_name' ];
2004-02-05 09:28:02 -05:00
}
// makes sure not to upload duplicates, rename duplicates
$i = 1 ;
$pathtofile2 = $pathtofile ;
$tmppathtofile = $pathtofile2 ;
$img2_name = $img1_name ;
while ( file_exists ( $pathtofile2 )) {
$pos = strpos ( $tmppathtofile , '.' . trim ( $imgtype ));
$pathtofile_start = substr ( $tmppathtofile , 0 , $pos );
$pathtofile2 = $pathtofile_start . '_' . zeroise ( $i ++ , 2 ) . '.' . trim ( $imgtype );
$img2_name = explode ( '/' , $pathtofile2 );
$img2_name = $img2_name [ count ( $img2_name ) - 1 ];
}
if ( file_exists ( $pathtofile ) && ! strlen ( $imgalt )) {
2004-03-01 01:13:32 -05:00
$i = explode ( ' ' , get_settings ( 'fileupload_allowedtypes' ));
$i = implode ( ', ' , array_slice ( $i , 1 , count ( $i ) - 2 ));
2004-02-05 09:28:02 -05:00
$moved = move_uploaded_file ( $img1 , $pathtofile2 );
// if move_uploaded_file() fails, try copy()
if ( ! $moved ) {
$moved = copy ( $img1 , $pathtofile2 );
}
if ( ! $moved ) {
2004-04-23 02:46:53 -04:00
die ( sprintf ( __ ( " Couldn't upload your file to %s. " ), $pathtofile2 ));
2004-02-05 09:28:02 -05:00
} else {
2004-04-18 03:10:44 -04:00
chmod ( $pathtofile2 , 0666 );
2004-02-05 09:28:02 -05:00
@ unlink ( $img1 );
}
2004-04-18 03:10:44 -04:00
//
2004-02-05 09:28:02 -05:00
// duplicate-renaming function contributed by Gary Lawrence Murphy
?>
2004-04-23 02:46:53 -04:00
< p >< strong >< ? php __ ( 'Duplicate File?' ) ?> </strong></p>
< p >< b >< em >< ? php printf ( __ ( " The filename '%s' already exists! " ), $img1_name ); ?> </em></b></p>
2004-04-23 20:16:27 -04:00
< p > < ? php printf ( __ ( " Filename '%1 \$ s' moved to '%2 \$ s' " ), $img1 , " $pathtofile2 - $img2_name " ) ?> </p>
2004-04-23 02:46:53 -04:00
< p >< ? php _e ( 'Confirm or rename:' ) ?> </p>
2004-02-05 09:28:02 -05:00
< form action = " upload.php " method = " post " enctype = " multipart/form-data " >
2004-03-01 01:13:32 -05:00
< input type = " hidden " name = " MAX_FILE_SIZE " value = " <?php echo get_settings('fileupload_maxk') *1024 ?> " />
2004-02-05 09:28:02 -05:00
< input type = " hidden " name = " img1_type " value = " <?php echo $img1_type ;?> " />
< input type = " hidden " name = " img1_name " value = " <?php echo $img2_name ;?> " />
< input type = " hidden " name = " img1_size " value = " <?php echo $img1_size ;?> " />
< input type = " hidden " name = " img1 " value = " <?php echo $pathtofile2 ;?> " />
< input type = " hidden " name = " thumbsize " value = " <?php echo $_REQUEST['thumbsize'] ;?> " />
< input type = " hidden " name = " imgthumbsizecustom " value = " <?php echo $_REQUEST['imgthumbsizecustom'] ;?> " />
2004-04-23 02:46:53 -04:00
< ? php _e ( 'Alternate name:' ) ?> <br /><input type="text" name="imgalt" size="30" class="uploadform" value="<?php echo $img2_name;?>" /><br />
2004-02-05 09:28:02 -05:00
< br />
2004-04-23 02:46:53 -04:00
< ? php _e ( 'Description:' ) ?> <br /><input type="text" name="imgdesc" size="30" class="uploadform" value="<?php echo $imgdesc;?>" />
2004-02-05 09:28:02 -05:00
< br />
2004-04-23 02:46:53 -04:00
< input type = " submit " name = " submit " value = " <?php _e('Rename') ?> " class = " search " />
2004-02-05 09:28:02 -05:00
</ form >
</ div >
< ? php
2004-10-08 10:59:52 -04:00
2004-02-05 09:28:02 -05:00
require ( 'admin-footer.php' );
die ();
}
if ( ! strlen ( $imgalt )) {
@ $moved = move_uploaded_file ( $img1 , $pathtofile ); //Path to your images directory, chmod the dir to 777
// move_uploaded_file() can fail if open_basedir in PHP.INI doesn't
// include your tmp directory. Try copy instead?
2004-04-18 03:10:44 -04:00
if ( ! $moved ) {
2004-02-05 09:28:02 -05:00
$moved = copy ( $img1 , $pathtofile );
}
// Still couldn't get it. Give up.
2004-08-30 04:16:55 -04:00
if ( ! $moved ) {
2004-04-23 02:46:53 -04:00
die ( sprintf ( __ ( " Couldn't upload your file to %s. " ), $pathtofile ));
2004-02-05 09:28:02 -05:00
} else {
2004-04-18 03:10:44 -04:00
chmod ( $pathtofile , 0666 );
2004-02-05 09:28:02 -05:00
@ unlink ( $img1 );
}
} else {
rename ( $img1 , $pathtofile )
2004-04-23 02:46:53 -04:00
or die ( sprintf ( __ ( " Couldn't upload your file to %s. " ), $pathtofile ));
2004-02-05 09:28:02 -05:00
}
2004-04-20 18:56:47 -04:00
if ( $_POST [ 'thumbsize' ] != 'none' ) {
if ( $_POST [ 'thumbsize' ] == 'small' ) {
2004-02-05 09:28:02 -05:00
$max_side = 200 ;
}
2004-04-20 18:56:47 -04:00
elseif ( $_POST [ 'thumbsize' ] == 'large' ) {
2004-02-05 09:28:02 -05:00
$max_side = 400 ;
}
2004-04-20 18:56:47 -04:00
elseif ( $_POST [ 'thumbsize' ] == 'custom' ) {
2004-10-01 20:46:30 -04:00
$max_side = intval ( $_POST [ 'imgthumbsizecustom' ]);
2004-02-05 09:28:02 -05:00
}
$result = wp_create_thumbnail ( $pathtofile , $max_side , NULL );
if ( $result != 1 ) {
print $result ;
}
}
2003-05-22 08:12:53 -04:00
if ( ereg ( 'image/' , $img1_type )) {
2004-03-01 01:13:32 -05:00
$piece_of_code = " <img src=" " . get_settings ( 'fileupload_url' ) . " / $img1_name " alt=" $imgdesc " /> " ;
2003-05-22 08:12:53 -04:00
} else {
2004-03-01 01:13:32 -05:00
$piece_of_code = " <a href=" " . get_settings ( 'fileupload_url' ) . " / $img1_name " title=" $imgdesc " /> $imgdesc </a> " ;
2003-05-22 08:12:53 -04:00
};
?>
2004-04-23 02:46:53 -04:00
< h3 >< ? php _e ( 'File uploaded!' ) ?> </h3>
< p >< ? php printf ( __ ( " Your file <code>%s</code> was uploaded successfully! " ), $img1_name ); ?> </p>
< p >< ? php _e ( 'Here’s the code to display it:' ) ?> </p>
2004-02-05 09:28:02 -05:00
< p >< code >< ? php echo $piece_of_code ; ?> </code>
2003-05-22 08:12:53 -04:00
</ p >
2004-04-23 02:46:53 -04:00
< p >< strong >< ? php _e ( 'Image Details' ) ?> </strong>: <br />
2004-02-05 09:28:02 -05:00
Name :
< ? php echo $img1_name ; ?>
2003-05-22 08:12:53 -04:00
< br />
2004-04-23 02:46:53 -04:00
< ? php _e ( 'Size:' ) ?>
< ? php echo round ( $img1_size / 1024 , 2 ); ?> <?php _e('<abbr title="Kilobyte">KB</abbr>') ?><br />
< ? php _e ( 'Type:' ) ?>
2004-02-05 09:28:02 -05:00
< ? php echo $img1_type ; ?>
2003-05-22 08:12:53 -04:00
</ p >
2004-02-05 09:28:02 -05:00
</ div >
2004-04-23 02:46:53 -04:00
< p >< a href = " upload.php " >< ? php _e ( 'Upload another' ) ?> </a></p>
2004-02-05 09:28:02 -05:00
< ? php
break ;
}
include ( 'admin-footer.php' );
2004-03-05 02:26:38 -05:00
?>