Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jan 2009
    Posts
    207
    Thanks
    29
    Thanked 0 Times in 0 Posts

    Image As Submit Button

    Can anyone help please.
    I have a form and I want to use a image as the input button.

    Form:
    PHP Code:
    <form method="post" enctype="multipart/form-data">
    <div><?php echo $message?></div><?php echo $max_file_size_tag?>
    File Upload: <input type="file" size="25" name="filename"><br /> <br />
    File   Name: <input type="text" size="40" name="mp3_real_name">  <br /><br />
    File   Album: <input type="text" size="40" name="uploader">  <br /> <br />
    <input type="submit" value="Upload" name="submit">
    </form>
    I have tried:
    PHP Code:
    <input type="image" name="submit" src="images/banana.png"  width="30"  height="30" borber="0" alt="SUBMIT!"

  • #2
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    Do you mind telling us what your actual issue is, other than your form is not actually submitting anywhere? (:

  • #3
    Regular Coder
    Join Date
    Jan 2009
    Posts
    207
    Thanks
    29
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Apostropartheid View Post
    Do you mind telling us what your actual issue is, other than your form is not actually submitting anywhere? (:
    Well with the basic but it submits perfect.
    When I change to an image button , it does not submit...

  • #4
    Regular Coder jdswebservice's Avatar
    Join Date
    Aug 2010
    Location
    Moon Township, PA
    Posts
    107
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Post the whole code for the page please.

  • #5
    Regular Coder
    Join Date
    Jan 2009
    Posts
    207
    Thanks
    29
    Thanked 0 Times in 0 Posts
    It's in two parts.
    file_upload.php includes file-upload.html @
    Code:
    // Load form template

    file-upload.html
    PHP Code:
    <br /><center><form method="post" enctype="multipart/form-data">
      <div><?php echo $message?></div><?php echo $max_file_size_tag?>

    File Upload: <input type="file" size="25" name="filename"><br /> <br />
    ...File   Name:<input type="text" size="40" name="mp3_real_name">  <br /><br />
    ...File   Album:<input type="text" size="40" name="uploader">  <br /> <br />
    <input type="submit" value="Upload" name="submit">
    </form></center>

    file_upload.php
    PHP Code:
    <?php



    // Folder to upload files to. Must end with slash /
    define('DESTINATION_FOLDER','./song_uploads/');

    // Maximum allowed file size, Kb
    // Set to zero to allow any size
    define('MAX_FILE_SIZE'0);

    // Upload success URL. User will be redirected to this page after upload.
    define('SUCCESS_URL','index.php');

    // Allowed file extensions. Will only allow these extensions if not empty.
    // Example: $exts = array('avi','mov','doc');
    $exts = array('mp3');

    // rename file after upload? false - leave original, true - rename to some unique filename
    define('RENAME_FILE'true);

    // put a string to append to the uploaded file name (after extension);
    // this will reduce the risk of being hacked by uploading potentially unsafe files;
    // sample strings: aaa, my, etc.
    define('APPEND_STRING''');

    // Need uploads log? Logs would be saved in the MySql database.
    define('DO_LOG'true);

    // MySql data (in case you want to save uploads log)
    define('DB_HOST','localhost'); // host, usually localhost
    define('DB_DATABASE','billy'); // database name
    define('DB_USERNAME','root'); // username
    define('DB_PASSWORD','root'); // password

    /* NOTE: when using log, you have to create mysql table first for this script.
    Copy paste following into your mysql admin tool (like PhpMyAdmin) to create table
    If you are on cPanel, then prefix _uploads_log on line 205 with your username, so it would be like myusername_uploads_log

    CREATE TABLE IF NOT EXISTS `mp3_uploads` (
      `mp3_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `mp3_real_name` text NOT NULL,
      `username` text NOT NULL,
      `mp3_filename` varchar(128) DEFAULT NULL,
      `mp3_size` int(10) DEFAULT '0',
      `mp3_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
      PRIMARY KEY (`mp3_id`),
      KEY `log_filename` (`mp3_filename`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;

    */

    ####################################################################
    ###  END OF SETTINGS.   DO NOT CHANGE BELOW
    ####################################################################

    // Allow script to work long enough to upload big files (in seconds, 2 days by default)
    @set_time_limit(172800);

    // following may need to be uncommented in case of problems
    // ini_set("session.gc_maxlifetime","10800");

    function showUploadForm($message='') {
      
    $max_file_size_tag '';
      if (
    MAX_FILE_SIZE 0) {
        
    // convert to bytes
        
    $max_file_size_tag "<input name='MAX_FILE_SIZE' value='".(MAX_FILE_SIZE*1024)."' type='hidden' >\n";
      }

      
    // Load form template
      
    include ('file-upload.html');
    }

    // errors list
    $errors = array();

    $message '';

    // we should not exceed php.ini max file size
    $ini_maxsize ini_get('upload_max_filesize');
    if (!
    is_numeric($ini_maxsize)) {
      if (
    strpos($ini_maxsize'M') !== false)
        
    $ini_maxsize intval($ini_maxsize)*1024*1024;
      elseif (
    strpos($ini_maxsize'K') !== false)
        
    $ini_maxsize intval($ini_maxsize)*1024;
      elseif (
    strpos($ini_maxsize'G') !== false)
        
    $ini_maxsize intval($ini_maxsize)*1024*1024*1024;
    }
    if (
    $ini_maxsize MAX_FILE_SIZE*1024) {
      
    $errors[] = "Alert! Maximum upload file size in php.ini (upload_max_filesize) is less than script's MAX_FILE_SIZE";
    }

    // show upload form
    if (!isset($_POST['submit'])) {
      
    showUploadForm(join('',$errors));
    }

    // process file upload
    else {
      
      while(
    true) {

        
    // make sure destination folder exists
        
    if (!@file_exists(DESTINATION_FOLDER)) {
          
    $errors[] = "Destination folder does not exist or no permissions to see it.";
          break;
        }

        
    // check for upload errors
        
    $error_code $_FILES['filename']['error'];
        if (
    $error_code != UPLOAD_ERR_OK) {
          switch(
    $error_code) {
            case 
    UPLOAD_ERR_INI_SIZE
              
    // uploaded file exceeds the upload_max_filesize directive in php.ini
              
    $errors[] = "File is too big (1).";
              break;
            case 
    UPLOAD_ERR_FORM_SIZE
              
    // uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form
              
    $errors[] = "File is too big (2).";
              break;
            case 
    UPLOAD_ERR_PARTIAL:
              
    // uploaded file was only partially uploaded.
              
    $errors[] = "Could not upload file (1).";
              break;
            case 
    UPLOAD_ERR_NO_FILE:
              
    // No file was uploaded
              
    $errors[] = "Could not upload file (2).";
              break;
            case 
    UPLOAD_ERR_NO_TMP_DIR:
              
    // Missing a temporary folder
              
    $errors[] = "Could not upload file (3).";
              break;
            case 
    UPLOAD_ERR_CANT_WRITE:
              
    // Failed to write file to disk
              
    $errors[] = "Could not upload file (4).";
              break;
            case 
    8:
              
    // File upload stopped by extension
              
    $errors[] = "Could not upload file (5).";
              break;
          } 
    // switch

          // leave the while loop
          
    break;
        }

        
    // get file name (not including path)
        
    $filename = @basename($_FILES['filename']['name']);

        
    // filename of temp uploaded file
        
    $tmp_filename $_FILES['filename']['tmp_name'];

        
    $file_ext = @strtolower(@strrchr($filename,"."));
        if (@
    strpos($file_ext,'.') === false) { // no dot? strange
          
    $errors[] = "Suspicious file name or could not determine file extension.";
          break;
        }
        
    $file_ext = @substr($file_ext1); // remove dot

        // check file type if needed
        
    if (count($exts)) {   /// some day maybe check also $_FILES['user_file']['type']
          
    if (!@in_array($file_ext$exts)) {
            
    $errors[] = "Files of this type are not allowed for upload.";
            break;
          }
        }

        
    // destination filename, rename if set to
        
    $dest_filename $filename;
        if (
    RENAME_FILE) {
          
    $dest_filename md5(uniqid(rand(), true)) . '.' $file_ext;
        }
        
    // append predefined string for safety
        
    $dest_filename $dest_filename APPEND_STRING;

        
    // get size
        
    $filesize intval($_FILES["filename"]["size"]); // filesize($tmp_filename);

        // make sure file size is ok
        
    if (MAX_FILE_SIZE && MAX_FILE_SIZE*10240000 $filesize) {
          
    $errors[] = "File is too big (3).";
          break;
        }

        if (!@
    move_uploaded_file($tmp_filename DESTINATION_FOLDER $dest_filename)) {
          
    $errors[] = "Could not upload file (6).";
          break;
        }

        if (
    DO_LOG) {
          
    // Establish DB connection
          
    $link = @mysql_connect(DB_HOSTDB_USERNAMEDB_PASSWORD);
          if (!
    $link) {
            
    $errors[] = "Could not connect to mysql.";
            break;
          }
          
    $res = @mysql_select_db(DB_DATABASE$link);
          if (!
    $res) {
            
    $errors[] = "Could not select database.";
            break;
          }
          
    $mp3_real_name mysql_real_escape_string($_POST['mp3_real_name']);
          
    $uploader mysql_real_escape_string($_POST['uploader']);
          
    $m_size $filesize;
          
    $m_fname mysql_real_escape_string($dest_filename);
          
    $sql "insert into `mp3_uploads` (`mp3_real_name`, `uploader`, `mp3_filename`, `mp3_size`) values ('$mp3_real_name', '$uploader', '$m_fname','$m_size')";
          
    $res = @mysql_query($sql);
          if (!
    $res) {
            
    $errors[] = "Could not run query.";
            break;
          }
          @
    mysql_free_result($res);
          @
    mysql_close($link);
        } 
    // if (DO_LOG)


        // redirect to upload success url
        
    header('Location: ' SUCCESS_URL);
        die();

        break;

      } 
    // while(true)

      // Errors. Show upload form.
      
    $message join('',$errors);
      
    showUploadForm($message);

    }

    ?>

  • #6
    Regular Coder jdswebservice's Avatar
    Join Date
    Aug 2010
    Location
    Moon Township, PA
    Posts
    107
    Thanks
    0
    Thanked 5 Times in 5 Posts
    your form is this

    Code:
    <br /><center><form method="post" enctype="multipart/form-data"> 
      <div><?php echo $message; ?></div><?php echo $max_file_size_tag; ?> 
    
    File Upload: <input type="file" size="25" name="filename"><br /> <br /> 
    ...File   Name:<input type="text" size="40" name="mp3_real_name">  <br /><br /> 
    ...File   Album:<input type="text" size="40" name="uploader">  <br /> <br /> 
    <input type="submit" value="Upload" name="submit"> 
    </form></center>
    You forgot something... this little bit here... made bold...

    Code:
    <form method="post" enctype="multipart/form-data" action="file_upload.php">
    Hope this helps!

  • #7
    New Coder
    Join Date
    Aug 2010
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think he's trying to use an image as his submit button.

    Why not do it with a CSS background? That's what I always do.

    Code:
    #form .submit-button {
      background:url(../img/submit-button.png) no-repeat;
      width:120px;
      height:30px;
      cursor:pointer;
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •