Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Senior Member
    Join Date
    Apr 2005
    Location
    Hatfield, England
    Posts
    855
    Member #
    9790
    PHP Code:
    $form['image'] = array(
    '#type' => 'file',
    '#title' => t('Upload Main Image'),
    '#default_value' => $node->image,
    '#size' => 48,
    '#description' => t('Upload Main Image.')
    ); 
    I have this in my form, it generates an image upload box. However the image isn't uploading and the name of the file isn't going into the database.

    How can i process to this to
    a) Get the file name to input into my database
    b) Actually make this upload this file to root/files

    Incase it is needed the full module can be found below.

    PHP Code:
    <?php
    // $Id$
    /**
    * @file
    * Provides a "portfolio" node type.
    */

    /**
    * Implementation of hook_node_info().
    */
    function portfolio_node_info() {
    // We return an array since a module can define multiple node types.
    // We're only defining one node type, type 'portfolio'.
    return array(
    'portfolio' => array(
    'name' => t('Portfolio'), // Required.
    'module' => 'portfolio'// Required.
    'description' => t('Add a portfolio item!'), // Required.
    'has_title' => TRUE,
    'title_label' => t('Title'),
    'has_body' => TRUE,
    'body_label' => t('Portfolio'),
    'locked' => TRUE
    )
    );
    }

    /**
    * Implementation of hook_menu().
    */
    function portfolio_menu($may_cache) {
    $items = array();
    // Do not cache this menu item during the development of this module.
    if (!$may_cache) {
    $items[] = array(
    'path' => 'node/add/portfolio',
    'title' => t('Portfolio'),
    'access' => user_access('create portfolio'),
    );
    }
    return 
    $items;
    }

    /**
    * Implementation of hook_perm().
    */
    function portfolio_perm() {
    return array(
    'create portfolio''edit own portfolio');
    }

    /**
    * Implementation of hook_access().
    */
    function portfolio_access($op$node) {
    global 
    $user;
    if (
    $op == 'create') {
    return (
    user_access('create portfolio'));
    }
    if (
    $op == 'update' || $op == 'delete') {
    return (
    user_access('edit own portfolio') && ($user->uid == $node->uid));
    }
    }

    /**
    * Implementation of hook_form().
    */
    function portfolio_form($node) {
    // Get metadata for this node type
    // (we use it for labeling title and body fields).
    // We defined this in portfolio_node_info().
    $form['#attributes']['enctype'] = 'multipart/form-data';

    $type node_get_types('type'$node);
    $form['title'] = array(
    '#type' => 'textfield',
    '#title' => check_plain($type->title_label),
    '#required' => TRUE,
    '#default_value' => $node->title,
    '#weight' => -5
    );
    $form['body_filter']['body'] = array(
    '#type' => 'textarea',
    '#title' => check_plain($type->body_label),
    '#default_value' => $node->body,
    '#rows' => 7,
    '#required' => TRUE
    );
    $form['body_filter']['filter'] = filter_form($node->format);

    $form['image_small'] = array(
    '#type' => 'file',
    '#title' => t('Upload Teaser Picture'),
    '#default_value' => $node->image_small,
    '#size' => 48,
    '#description' => t('Upload Teaser Picture.')
    );
    $form['image'] = array(
    '#type' => 'file',
    '#title' => t('Upload Main Image'),
    '#default_value' => $node->image,
    '#size' => 48,
    '#description' => t('Upload Main Image.')
    );
    return 
    $form;
    }

    /**
    * Implementation of hook_validate().
    */
    function portfolio_validate($node) {
    // Enforce a minimum word length of 3.

    }

    /**
    * Implementation of hook_insert().
    */
    function portfolio_insert($node) {
    db_query("INSERT INTO {portfolio} (nid, vid, image_small, image) VALUES (%d, %d, '%s', '%s')",
    $node->nid$node->vid$node->image_small$node->image);
    }

    /**
    * Implementation of hook_update().
    */
    function portfolio_update($node) {
    if (
    $node->revision) {
    portfolio_insert($node);
    }
    else {
    db_query("UPDATE {portfolio} SET image_small = '%s', image = '%s' WHERE vid = %d",
    $node->image_small$node->image$node->vid);
    }
    }

    /**
    * Implementation of hook_delete().
    */
    function portfolio_delete(&$node) {
    // Delete the related information we were saving for this node.
    db_query('DELETE FROM {portfolio} WHERE nid = %d'$node->nid);
    }

    /**
    * Implementation of hook_load().
    */
    function portfolio_load($node) {
    return 
    db_fetch_object(db_query('SELECT image_small, image FROM {portfolio} WHERE vid = %d',
    $node->vid));
    }

  2.  

  3. #2
    Junior Member santiagov's Avatar
    Join Date
    Jul 2014
    Posts
    1
    Member #
    39656
    Have you try webforms, you just create the fields types and has a upload field to get what you looking for, you don't have to de any php at all


    Sent from my iPhone using Tapatalk


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:24 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com