The following code will get content from url and create a note with attachment file.
$url = 'http://forum.epesibim.com/t/bug-reports';
$filename = 'art-1200x1200.html';
$content = file_get_contents($url);
$file_id = Utils_FileStorageCommon::write_content($filename, $content);
$meta = Utils_FileStorageCommon::meta($file_id);
$user = Acl::get_user();
$note = Utils_RecordBrowserCommon::new_record('utils_attachment', array('local'=>'contact/1', 'note'=>$url, 'permission'=>0, 'func'=>null, 'args'=>null,'sticky'=>1, 'title'=>$url,'crypted'=>0));
Utils_AttachmentCommon::add_file($note, $user, $filename, $meta['file']);
Error:
Type: E_USER_ERROR (256)
Message: postgres8 error: [-5: ERROR: duplicate key value violates unique constraint "utils_filestorage_files_hash_key" DETAIL: Key (hash)=(7f39d7ce4aa4cb4cbb457a1ce27012bc3d102bd7902647be84110616091618d5252a6c646cdb11d10c63a483789c31f5244cdab7dd9282fe0e36f7dcfd983eda) already exists.] in EXECUTE("INSERT INTO utils_filestorage_files(filename,uploaded_on,hash) VALUES(?,?,?)")
File: /var/www/epesi/libs/adodb/adodb-errorhandler.inc.php
Line=77
error backtrace:
[PHP core called function]
function called: handle_epesi_error(256, "postgres8 error: [-5: ERROR: duplicate key value violates unique constraint \"utils_filestorage_files_hash_key\" DETAIL: Key (hash)=(7f39d7ce4aa4cb4cbb457a1ce27012bc3d102bd7902647be84110616091618d5252a6c646cdb11d10c63a483789c31f5244cdab7dd9282fe0e36f7dcfd983eda) already exists.] in EXECUTE(\"INSERT INTO utils_filestorage_files(filename,uploaded_on,hash) VALUES(?,?,?)\") ", "/var/www/epesi/libs/adodb/adodb-errorhandler.inc.php", 77, Array ("postgres8", "EXECUTE", -5, "ERROR: duplicate key value violates unique constraint \"utils_filestorage_files_hash_key\" DETAIL: Key (hash)=(7f39d7ce4aa4cb4cbb457a1ce27012bc3d102bd7902647be84110616091618d5252a6c646cdb11d10c63a483789c31f5244cdab7dd9282fe0e36f7dcfd983eda) already exists.", "INSERT INTO utils_filestorage_files(filename,uploaded_on,hash) VALUES(?,?,?)", Array (#3), Object (ADODB_postgres8), "INSERT INTO utils_filestorage_files(filename,uploaded_on,hash) VALUES(?,?,?)", Array (#3), "postgres8 error: [-5: ERROR: duplicate key value violates unique constraint \"utils_filestorage_files_hash_key\" DETAIL: Key (hash)=(7f39d7ce4aa4cb4cbb457a1ce27012bc3d102bd7902647be84110616091618d5252a6c646cdb11d10c63a483789c31f5244cdab7dd9282fe0e36f7dcfd983eda) already exists.] in EXECUTE(\"INSERT INTO utils_filestorage_files(filename,uploaded_on,hash) VALUES(?,?,?)\") "))
File: /var/www/epesi/libs/adodb/adodb-errorhandler.inc.php
line 77
function called: trigger_error("postgres8 error: [-5: ERROR: duplicate key value violates unique constraint \"utils_filestorage_files_hash_key\" DETAIL: Key (hash)=(7f39d7ce4aa4cb4cbb457a1ce27012bc3d102bd7902647be84110616091618d5252a6c646cdb11d10c63a483789c31f5244cdab7dd9282fe0e36f7dcfd983eda) already exists.] in EXECUTE(\"INSERT INTO utils_filestorage_files(filename,uploaded_on,hash) VALUES(?,?,?)\") ", 256)
File: /var/www/epesi/libs/adodb/adodb.inc.php
line 1071
function called: ADODB_Error_Handler("postgres8", "EXECUTE", -5, "ERROR: duplicate key value violates unique constraint \"utils_filestorage_files_hash_key\" DETAIL: Key (hash)=(7f39d7ce4aa4cb4cbb457a1ce27012bc3d102bd7902647be84110616091618d5252a6c646cdb11d10c63a483789c31f5244cdab7dd9282fe0e36f7dcfd983eda) already exists.", "INSERT INTO utils_filestorage_files(filename,uploaded_on,hash) VALUES(?,?,?)", Array ("art-1200x1200.png", "2016-08-09 22:11:46", "7f39d7ce4aa4cb4cbb457a1ce27012bc3d102bd7902647be84110616091618d5252a6c646cdb11d10c63a483789c31f5244cdab7dd9282fe0e36f7dcfd983eda"), "Object (ADODB_postgres8)")
File: /var/www/epesi/libs/adodb/adodb.inc.php
line 1042
function called: _Execute("INSERT INTO utils_filestorage_files(filename,uploaded_on,hash) VALUES(?,?,?)", Array ("art-1200x1200.png", "2016-08-09 22:11:46", "7f39d7ce4aa4cb4cbb457a1ce27012bc3d102bd7902647be84110616091618d5252a6c646cdb11d10c63a483789c31f5244cdab7dd9282fe0e36f7dcfd983eda"))
[PHP core called function]
function called: Execute("INSERT INTO utils_filestorage_files(filename,uploaded_on,hash) VALUES(?,?,?)", Array ("art-1200x1200.png", "2016-08-09 22:11:46", "7f39d7ce4aa4cb4cbb457a1ce27012bc3d102bd7902647be84110616091618d5252a6c646cdb11d10c63a483789c31f5244cdab7dd9282fe0e36f7dcfd983eda"))
File: /var/www/epesi/include/database.php
line 360
function called: call_user_func_array(Array (Object (ADODB_postgres8), "Execute"), Array ("INSERT INTO utils_filestorage_files(filename,uploaded_on,hash) VALUES(?,?,?)", Array (#3)))
File: /var/www/epesi/modules/Utils/FileStorage/FileStorageCommon_0.php
line 29
function called: Execute("INSERT INTO utils_filestorage_files(filename,uploaded_on,hash) VALUES(%s,%T,%s)", Array ("art-1200x1200.png", 1470755506, "7f39d7ce4aa4cb4cbb457a1ce27012bc3d102bd7902647be84110616091618d5252a6c646cdb11d10c63a483789c31f5244cdab7dd9282fe0e36f7dcfd983eda"))