Note that there are some explanatory texts on larger screens.

plurals
  1. POdrupal 7- moving and displaying uploaded image in custom module
    text
    copied!<p>I am developing a custom module in which I want to:</p> <ol> <li>Upload an image through a form.</li> <li>Move image from default folder to my desired folder.</li> <li>And finally display the image under the same form (below the submit button).</li> </ol> <p>I've achieved the first goal by implementing hook_menu and hook_form but I am stucked very badly in the remaining two goals for last 3 days. Whenever I try to move uploaded image from default folder I get the error message of "Invalid location" and for the third point I didn't understand what to do? I want when the user selects the image and submits the form the image is displayed on the same page under the submit button. Any help would be really appreciated. Here's my code:-</p> <pre><code>function create_ad_form($form, &amp;$form_submit) { ... $form['image_file'] = array( '#title' =&gt; t('Upload Banner:'), '#type' =&gt; 'file' ); $form['#attributes']['enctype'] = 'multipart/form-data'; ... } function create_ad_form_submit($form, &amp;$form_state) { $module=drupal_get_path('module', 'create_ad'); $validators = array(); $file = file_save_upload('image_file', $validators,"public://",FILE_EXISTS_RENAME); if ($file) { $file-&gt;status=FILE_STATUS_PERMANENT; file_save($file); $result = file_unmanaged_copy($file, $module, FILE_EXISTS_RENAME); if ($result == 1) { } else { drupal_set_message('Couldn\'t copy file: '.$file-&gt;name); } } else { form_set_error('create_ad', t("Failed to save the file.")); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload