• hi i need help with my plugin basicaly its an uploader that renames the fille that’s been uploaded but it dont seem to upload the file can you tell me whats wrong?

    <?php
    /*
    Plugin Name: Comic Test
    Plugin URI: http://ww.wp.xz.cn
    Description: Menu Test
    Author: Nobody
    Author URI: http://example.com
    */
    
    add_action('admin_menu', 'mt_add_pages');
    
    function mt_add_pages() {
    
        add_menu_page('Comic Uploader', 'Comic Uploader', 8, __FILE__, 'com_tl_page');
    	 add_submenu_page(__FILE__, 'Test 7', 'Test 7', 7, 'sub-page', 'com_lv7_page');
    
    }
    
    function com_tl_page() {
        echo "<h2>Test Toplevel</h2>";
    echo '<br />You are here http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    echo '<br />'.$_SERVER['DOCUMENT_ROOT'];
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $date = $_POST['date'];
    // Your file name you are uploading
    $file_name = $HTTP_POST_FILES['ufile']['name'];
    
    // random 4 digit to add to our file name
    // some people use date and time in stead of random digit
    $random_digit=rand(0000,9999);
    
    //combine random digit to you file name to create new file name
    //use dot (.) to combile these two variables
    
    $new_file_name=$date.$file_name;
    $npath = 'http://'.$_SERVER['HTTP_HOST'];
    
    //set where you want to store files
    //in this example we keep file in folder upload
    //$new_file_name = new upload file name
    //for example upload file name cartoon.gif . $path will be upload/cartoon.gif
    $path=$npath."/comics/".$new_file_name;
    if($ufile !=none)
    {
    if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
    {
    echo "Successful<BR />";
    
    //$new_file_name = new file name
    //$HTTP_POST_FILES['ufile']['size'] = file size
    //$HTTP_POST_FILES['ufile']['type'] = type of file
    echo "File Name :".$new_file_name."<BR />";
    echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR />";
    echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR />";
    }
    else
    {
    echo "<br />Error :".$path."<br />";
    echo "File Name :".$file_name."<BR />";
    }
    }
    }
    else {
    ?>
    <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <form action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
    <td>
    <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
    <tr>
    <td colspan="2"><strong>Comic Upload </strong></td>
    </tr>
    <tr>
      <td>Date to be first shown:</td>
      <td><input name="date" type="text" id="date" value="YYYY-MM-DD"></td>
    </tr>
    <tr>
    <td width="23%">Select file</td>
    <td width="77%"><input name="ufile" type="file" id="ufile" size="50" /></td>
    </tr>
    
    <tr>
      <td colspan="2" align="center"><input type="submit" name="Submit" value="Upload" /></td>
    </tr>
    </table>
    </td>
    </form>
    </tr>
    </table>
    <?
    }
    }
    function com_lv7_page() {
    echo "This tab only appears if you're level 7 or more in other words editor and more";
    }
    
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Need help’ is closed to new replies.