| 6 file.inc | file_set_status(&$file, $status) |
Set the status of a file.
Parameters
$file : A Drupal file object.
$status: A status value to set the file to. One of:
Return value
FALSE on failure, TRUE on success and $file->status will contain the status.
Related topics
File
- includes/
file.inc, line 844 - API for handling file uploads and server file management.
Code
<?php
function file_set_status(&$file, $status) {
if (db_query('UPDATE {files} SET status = %d WHERE fid = %d', $status, $file->fid)) {
$file->status = $status;
return TRUE;
}
return FALSE;
}
?> Login or register to post comments
Comments
Values for $status
Use the following constants for the $status parameter:
Drupal 7
This function no longer exists in Drupal 7. To achieve the same thing you must set the status parameter on a file object then use file_save to save it:
// First obtain a file object, for example by file_load...
$file = file_load(10);
// Or as another example, the result of a file_save_upload...
$file = file_save_upload('upload', array(), 'public://', FILE_EXISTS_REPLACE);
// Now you can set the status
$file->status = FILE_STATUS_PERMANENT;
// And save the status.
file_save($file);