Всем привет. У меня ошибка.
Вот js:
<script type="text/javascript">
jQuery(document).ready(function() {
$('body').on('click', '.del_urls', function() {
var parent = $(this).parent();
var message = $(this).attr("title");
var dlink = $(this).attr("href");
var answer = confirm(message);
if (answer) {
$.ajax({
type: "GET",
url: dlink,
success: function(msg) {
if (msg = "ok") {
parent.remove();
console.log("ok");
}
}
});
}
return false;
});
if (jQuery().uploadify) {
$('#uploadify').uploadify({
'debug': false,
'buttonText': 'Загрузка файлов',
'buttonCursor': 'pointer',
'uploader': 'engine/uploadify/upload-uploadify.php',
'swf': 'engine/uploadify/uploadify.swf',
'multi': true,
'auto': true,
'height': '30',
'width': '100%',
'requeueErrors': false,
'fileSizeLimit': '512000', // expects input in kb
'cancelImage': 'engine/uploadify/bcancel.png',
'checkExisting': 'engine/uploadify/uploadify-check-exists.php',
'postData': {
'news_id': '{$row['
id ']}'
},
onUploadProgress: function() {
$('#loader').show();
},
onUploadSuccess: function(file, data, response) {
var data = $.parseJSON(data);
if (data.msg = "ok") {
$('#load_urls').prepend(data.url);
}
},
onSelectError: function(file, errorCode, errorMsg) {
//alert(file + ' Error ' + errorCode +':'+errorMsg);
},
onUploadError: function(file, errorCode, errorMsg, errorString) {
alert(errorMsg);
}
});
}
});
</script>
А вот php:
define( 'DATALIFEENGINE', true );
define( 'ROOT_DIR', substr( dirname( __FILE__ ), 0, -17 ) );
define( 'ENGINE_DIR', ROOT_DIR . '/engine' );
if($_SERVER['HTTP_HOST']!=="site.com") die();
require_once ENGINE_DIR . '/data/config.php';
require_once ENGINE_DIR . '/classes/mysql.php';
require_once ENGINE_DIR . '/data/dbconfig.php';
require_once ENGINE_DIR . '/inc/include/functions.inc.php';
$poddomen=parse_url($config['poddomen_url']);
define( 'PREFIX_DIR', date("m-Y")."/" );
define( 'UPLOAD_DIR', substr( dirname( __FILE__ ), 0, -17-strlen($_SERVER['HTTP_HOST']) ).$poddomen['host']."/files/" );
$_TIME = time ();
if (isset($_REQUEST['del'])) {
$id=intval($_REQUEST['id']);
$row = $db->super_query( "SELECT * FROM " . PREFIX . "_poddomen_files WHERE news_id = '{$id}'" );
if($row) {
$urls=$row['files'];
$urls=str_replace($_REQUEST['f']."||", "", $urls);
if (strlen($urls)>8) {
$row2=$db->query( "UPDATE " . PREFIX . "_poddomen_files SET files='{$urls}' WHERE news_id='{$id}'" );
if ($row2) {
@unlink(UPLOAD_DIR.$_REQUEST['f']);
echo "ok";
}
} else {
$db->query( "DELETE FROM " . PREFIX . "_poddomen_files WHERE news_id='{$id}'" );
@unlink(UPLOAD_DIR.$_REQUEST['f']);
}
}
}
if (!empty($_FILES)) {
if( intval( $_REQUEST['news_id'] ) ) $news_id = intval( $_REQUEST['news_id'] ); else $news_id = 0;
if( !is_dir( UPLOAD_DIR . PREFIX_DIR ) ) {
@mkdir( UPLOAD_DIR . PREFIX_DIR, 0777 );
@chmod( UPLOAD_DIR . PREFIX_DIR, 0777 );
}
if( !is_dir( UPLOAD_DIR . PREFIX_DIR ) ) {
die("Ne vozmozhno sozdat papku".UPLOAD_DIR . PREFIX_DIR);
}
if (!is_writable(UPLOAD_DIR . PREFIX_DIR)) {
die("Papka ".UPLOAD_DIR . PREFIX_DIR." no dostupna dlya zapisi");
}
$tempFile = $_FILES['Filedata']['tmp_name'];
$new_name = time()."_".$_FILES['Filedata']['name'];
$targetFile = rtrim(UPLOAD_DIR . PREFIX_DIR,'/') . '/' .$new_name;
$fileTypes = array('jpg','jpeg','gif','png','zip','mp4','rar');
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
$row = $db->super_query( "SELECT * FROM " . PREFIX . "_poddomen_files WHERE news_id = '{$news_id}'" );
if($row) {
$files=PREFIX_DIR.$new_name."||".$row['files'];
$db->query( "UPDATE " . PREFIX . "_poddomen_files SET news_id='{$news_id}', files='{$files}' WHERE news_id='{$news_id}'" );
} else {
$db->query( "INSERT INTO " . PREFIX . "_poddomen_files (news_id, files) values ('{$news_id}', '".PREFIX_DIR.$new_name."||')" );
}
$url=$config['poddomen_url'] . 'files/' . PREFIX_DIR.$new_name;
$insert="<div><input type=\"text\" value=\"".$url."\"><a class=\"del_urls\" title=\"Удалить файл {$new_name}?\" href=\"engine/ajax/uploads.php?id={$news_id}&f=".PREFIX_DIR.$new_name."&del\">del</a></div>";
echo json_encode(array("msg"=>"ok", "url"=>"{$insert}"));
} else {
echo 'Invalid file type.';
}
}
// Это еще код!
$pod_files = $db->super_query( "SELECT * FROM " . PREFIX . "_poddomen_files WHERE news_id = '{$id}'" );
if ($pod_files) {
$pod_urls = rtrim($pod_files['files'], "||");
$pod_urls = explode("||", $pod_urls);
$echo_pod_urls = "";
foreach ($pod_urls as $pod_url) {
$f_name = end(explode("/", $pod_url));
$echo_pod_urls .= <<<HTML
<div>
<input type="text" value="{$config['poddomen_url']}files/{$pod_url}" />
<a class="del_urls" title="Удалить файл {$f_name}?" href="engine/uploadify/upload-uploadify.php?id={$id}&f={$pod_url}&del">del</a>
</div>
HTML;
}
}
else $echo_pod_urls = "";