Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Apress.Pro.Drupal.7.Development.3rd.Edition.Dec.2010.pdf
Скачиваний:
73
Добавлен:
14.03.2016
Размер:
12.64 Mб
Скачать

CHAPTER 14 WORKING WITH FILES

request, attempts to upload files of a size greater than post_max_size will fail due to the amount of POST data being sent.

; Maximum size of POST data that PHP will accept. post_max_size = 8M

The File Uploads section of php.ini contains several more important settings. Here you can determine whether file uploads are allowed and what the maximum file size for uploaded files should be.

;;;;;;;;;;;;;;;;

;File Uploads ;

;;;;;;;;;;;;;;;;

;Whether to allow HTTP file uploads. file_uploads = On

;Temporary directory for HTTP uploaded files (will use system default if not

;specified).

;upload_tmp_dir =

; Maximum allowed size for uploaded files. upload_max_filesize = 20M

If file uploads seem to be failing, check that these settings are not at fault. Also, note that upload_max_filesize should be less than post_max_size, which should be less than memory_limit:

upload_max_filesize < post_max_size < memory_limit.

Two final settings that can leave you stumped are max_execution_time and max_input_time. If your script exceeds these limits while uploading a file, PHP will terminate your script. Check these settings if you see uploads from slow Internet connections failing.

;;;;;;;;;;;;;;;;;;;

; Resource Limits ;

;;;;;;;;;;;;;;;;;;;

max_execution_time = 60 ; Maximum execution time of each script, in seconds ; xdebug uses this, so set it very high for debugging

max_input_time = 60 ; Maximum amount of time each script may spend ; parsing request data

When debugging, you’ll want to have max_execution_time set at a high value (e.g., 1600) so the debugger does not time out. Bear in mind, however, that if your server is very busy, it is possible to tie up Apache processes for a long time while the files are uploaded, raising a potential scalability concern.

Media Handling

The file API (found in includes/file.inc) doesn’t provide a generic user interface for uploading files. To fill that gap for most end users, the field API (see Chapter 4) provides the functionality to address most file upload requirements.

326

CHAPTER 14 WORKING WITH FILES

Upload Field

To enable file uploads for a content type, you must first add a field to the content type for uploading files. To add a field to a content type, navigate to Structure -> Content Types. On the Content types page, click the manage fields link for the content type that you want to add the file upload capability to and add a new file field to the content type. Once added to the content type, the file upload field will appear on the content editing screen for that content type, as shown in Figure 14-2.

Figure 14-2. The “File attachments” field added to the node form

After a file has been uploaded on the node edit form, Drupal can add download links to uploaded files underneath the node body. The links are visible to those who have “view uploaded files” permission, as shown in Figure 14-3.

Figure 14-3. A generic list view of files uploaded to a node

327

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]