Jump to content

witchy478

Members
  • Posts

    38
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

witchy478's Achievements

Member

Member (2/5)

0

Reputation

  1. I forgot to add my js files this is site.js $(function() { $('#upload_file').submit(function(e) { e.preventDefault(); $.ajaxFileUpload({ url :'./upload/upload_file/', secureuri :false, fileElementId :'userfile', dataType : 'json', data : { 'title' : $('#title').val() }, success : function (data, status) { if(data.status != 'error') { $('#files').html('<p>Reloading files...</p>'); refresh_files(); $('#title').val(''); } alert(data.msg); } }); return false; }); refresh_files(); $('.delete_file_link').live('click', function(e) { e.preventDefault(); if (confirm('Are you sure you want to delete this file?')) { var link = $(this); $.ajax({ url : './upload/delete_file/' + link.data('file_id'), dataType : 'json', success : function (data) { if (data.status == "success") { link.parents('li').fadeOut('fast', function() { $(this).remove(); if ($('#files li').length == 0) { $('#files').html('<p>No Files Uploaded</p>'); } }); } else { alert(data.msg); } } }); } }); }); function refresh_files() { $.get('./upload/files/') .success(function (data){ $('#files').html(data); }); } and this is ajaxfileupload.js jQuery.extend({ createUploadIframe: function(id, uri) { //create frame var frameId = 'jUploadFrame' + id; var iframeHtml = '<iframe id="' + frameId + '" name="' + frameId + '" style="position:absolute; top:-9999px; left:-9999px"'; if(window.ActiveXObject) { if(typeof uri== 'boolean'){ iframeHtml += ' src="' + 'javascript:false' + '"'; } else if(typeof uri== 'string'){ iframeHtml += ' src="' + uri + '"'; } } iframeHtml += ' />'; jQuery(iframeHtml).appendTo(document.body); return jQuery('#' + frameId).get(0); }, createUploadForm: function(id, fileElementId, data) { //create form var formId = 'jUploadForm' + id; var fileId = 'jUploadFile' + id; var form = jQuery('<form action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>'); if(data) { for(var i in data) { jQuery('<input type="hidden" name="' + i + '" value="' + data[i] + '" />').appendTo(form); } } var oldElement = jQuery('#' + fileElementId); var newElement = jQuery(oldElement).clone(); jQuery(oldElement).attr('id', fileId); jQuery(oldElement).before(newElement); jQuery(oldElement).appendTo(form); //set attributes jQuery(form).css('position', 'absolute'); jQuery(form).css('top', '-1200px'); jQuery(form).css('left', '-1200px'); jQuery(form).appendTo('body'); return form; }, ajaxFileUpload: function(s) { // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout s = jQuery.extend({}, jQuery.ajaxSettings, s); var id = new Date().getTime() var form = jQuery.createUploadForm(id, s.fileElementId, (typeof(s.data)=='undefined'?false:s.data)); var io = jQuery.createUploadIframe(id, s.secureuri); var frameId = 'jUploadFrame' + id; var formId = 'jUploadForm' + id; // Watch for a new set of requests if ( s.global && ! jQuery.active++ ) { jQuery.event.trigger( "ajaxStart" ); } var requestDone = false; // Create the request object var xml = {} if ( s.global ) jQuery.event.trigger("ajaxSend", [xml, s]); // Wait for a response to come back var uploadCallback = function(isTimeout) { var io = document.getElementById(frameId); try { if(io.contentWindow) { xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null; xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document; }else if(io.contentDocument) { xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null; xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document; } }catch(e) { //jQuery.handleError(s, xml, null, e); console.log('ERROR', s, xml, null, e); } if ( xml || isTimeout == "timeout") { requestDone = true; var status; try { status = isTimeout != "timeout" ? "success" : "error"; // Make sure that the request was successful or notmodified if ( status != "error" ) { // process the data (runs the xml through httpData regardless of callback) var data = jQuery.uploadHttpData( xml, s.dataType ); // If a local callback was specified, fire it and pass it the data if ( s.success ) s.success( data, status ); // Fire the global callback if( s.global ) jQuery.event.trigger( "ajaxSuccess", [xml, s] ); } else { //jQuery.handleError(s, xml, status); console.log('ERROR', s, xml, status); } } catch(e) { status = "error"; console.log('ERROR', s, xml, status, e); //jQuery.handleError(s, xml, status, e); } // The request was completed if( s.global ) jQuery.event.trigger( "ajaxComplete", [xml, s] ); // Handle the global AJAX counter if ( s.global && ! --jQuery.active ) jQuery.event.trigger( "ajaxStop" ); // Process result if ( s.complete ) s.complete(xml, status); jQuery(io).unbind() setTimeout(function() { try { jQuery(io).remove(); jQuery(form).remove(); } catch(e) { console.log('ERROR', s, xml, null, e); //jQuery.handleError(s, xml, null, e); } }, 100) xml = null } } // Timeout checker if ( s.timeout > 0 ) { setTimeout(function(){ // Check to see if the request is still happening if( !requestDone ) uploadCallback( "timeout" ); }, s.timeout); } try { var form = jQuery('#' + formId); jQuery(form).attr('action', s.url); jQuery(form).attr('method', 'POST'); jQuery(form).attr('target', frameId); if(form.encoding) { jQuery(form).attr('encoding', 'multipart/form-data'); } else { jQuery(form).attr('enctype', 'multipart/form-data'); } jQuery(form).submit(); } catch(e) { console.log('ERROR', s, xml, null, e); //jQuery.handleError(s, xml, null, e); } jQuery('#' + frameId).load(uploadCallback ); return {abort: function () {}}; }, uploadHttpData: function( r, type ) { var data = !type; data = type == "xml" || data ? r.responseXML : r.responseText; // If the type is "script", eval it in global context if ( type == "script" ) jQuery.globalEval( data ); // Get the JavaScript object, if JSON is used. if ( type == "json" ) eval( "data = " + data ); // evaluate scripts within html if ( type == "html" ) jQuery("<div>").html(data).evalScripts(); return data; } })
  2. Hi I was busy doing a tutorial called How to Upload Files with CodeIgniter and AJAX, I did everything like it said but it's not uploading or saving the content. this is the upload controller <?php class Upload extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('files_model'); $this->load->database(); $this->load->helper('url'); } public function index() { $this->load->view('upload'); } public function upload_file() { $status = ""; $msg = ""; $file_element_name = 'userfile'; if (empty($_POST['title'])) { $status = "error"; $msg = "Please enter a title"; } if ($status != "error") { $config['upload_path'] = './files/'; $config['allowed_types'] = 'gif|jpg|png|doc|txt'; $config['max_size'] = 1024 * 8; $config['encrypt_name'] = TRUE; $this->load->library('upload', $config); if (!$this->upload->do_upload($file_element_name)) { $status = 'error'; $msg = $this->upload->display_errors('', ''); } else { $data = $this->upload->data(); $file_id = $this->files_model->insert_file($data['file_name'], $_POST['title']); if($file_id) { $status = "success"; $msg = "File successfully uploaded"; } else { unlink($data['full_path']); $status = "error"; $msg = "Something went wrong when saving the file, please try again."; } } @unlink($_FILES[$file_element_name]); } echo json_encode(array('status' => $status, 'msg' => $msg)); } public function files() { $files = $this->files_model->get_files(); $this->load->view('files', array('files' => $files)); } public function delete_file($file_id) { if ($this->files_model->delete_file($file_id)) { $status = 'success'; $msg = 'File successfully deleted'; } else { $status = 'error'; $msg = 'Something went wrong when deleteing the file, please try again'; } echo json_encode(array('status' => $status, 'msg' => $msg)); } } This is my files_model <?php class Files_Model extends CI_Model { public function insert_file($filename, $title) { $data = array( 'filename' => $filename, 'title' => $title ); $this->db->insert('files', $data); return $this->db->insert_id(); } public function delete_file($file_id) { $file = $this->get_file($file_id); if (!$this->db->where('id', $file_id)->delete('files')) { return FALSE; } unlink('./files/' . $file->filename); return TRUE; } public function get_files() { return $this->db->select() ->from('files') ->get() ->result(); } public function get_file($file_id) { return $this->db->select() ->from('files') ->where('id', $file_id) ->get() ->row(); } } This is my upload view <!doctype html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script src="<?php echo base_url()?>js/site.js"></script> <script src="<?php echo base_url()?>js/ajaxfileupload.js"></script> <link href="<?php echo base_url()?>css/style.css" rel="stylesheet" /> </head> <body> <h1>Upload File</h1> <p class="error"></p> <form method="post" action="<?php echo site_url('/upload/upload')?>" id="upload_file"> <label for="title">Title</label> <br /> <input type="text" name="title" id="title" value="" /> <br /> <label for="userfile">File</label> <br /> <input type="file" name="userfile" id="userfile" size="20" /> <br /> <input type="submit" name="submit" id="submit" /> </form> <h2>Files</h2> <div id="files"></div> </body> </html> This is my files view <?php if (isset($files) && count($files)) { ?> <ul> <?php foreach ($files as $file) { ?> <li class="image_wrap"> <a href="#" class="delete_file_link" data-file_id="<?php echo $file->id?>">Delete</a> <strong><?php echo $file->title?></strong> <br /> <?php echo $file->filename?> </li> <?php } ?> </ul> </form> <?php } else { ?> <p>No Files Uploaded</p> <?php } ?>
  3. Hi I'm trying to insert images and text into my database, I have found tutorials on how to insert them but the only give it in single forms. For example they give a tutorial to only insert images. So I would like to know how to combine the two of them. I have tried but it isn't working I get the text but I don't get the image file. This is my controller <?php class Bras extends CI_Controller{ public function __construct() { parent::__construct(); $this->load->model('bras_model'); $this->load->helper('url'); $this->load->helper('form'); } function index() { $data['title'] = "Voluptuous Decadents"; $data['heading'] = "Bras"; $data['query'] = $this->db->get('bras'); $this->load->view('layout'); $this->load->view('bras/create', $data); } function bras_view(){ $data['title'] = "Voluptuous Decadents"; $data['heading'] = "Bras"; $this->db->where('slug', $this->uri->segment(3)); $data['query'] = $this->db->get('bras'); $this->load->view('layout'); $this->load->view('bras/bras_view', $data); } public function create() { $this->load->helper('form'); $this->load->library('form_validation'); $data['title'] = 'Create a bra item'; $this->form_validation->set_rules('title', 'Title', 'required'); $this->form_validation->set_rules('content', 'content', 'required'); if ($this->form_validation->run() === FALSE) { $this->load->view('templates/header', $data); $this->load->view('bras/create'); $this->load->view('templates/footer'); } else { $this->bras_model->set_bras(); $this->load->view('bras/success'); } } function do_upload() { $config = array( 'upload_path' => './uploads/', 'allowed_types' => 'gif|jpg|png', 'max_size' => '100', 'max_width' => '1024', 'max_height' => '768', 'encrypt_name' => true, ); $this->load->library('upload', $config); if (!$this->upload->do_upload()) { $error = array('error' => $this->upload->display_errors()); $this->load->view('bras/create', $error); } else { $upload_data = $this->upload->data(); $data_ary = array( 'file' => $upload_data['file_name'], ); $this->load->database(); $this->db->insert('bras', $data_ary); $data = array('upload_data' => $upload_data); $this->load->view('bras/success', $data); } } } ?> This is my model <?php class Bras_model extends CI_Model { public function __construct() { $this->load->database(); } public function get_bras() { $query = $this->db->get('bras'); } public function set_bras() { $this->load->helper('url'); $slug = url_title($this->input->post('title'), 'dash', TRUE); $data = array( 'title' => $this->input->post('title'), 'slug' => $slug, 'content' => $this->input->post('content'), 'file' => $this->input->post('file_name'), 'price' => $this->input->post('price'), ); return $this->db->insert('bras', $data); } } ?> this is my view <h2>Create a news item</h2> <?php echo validation_errors(); ?> <?php echo form_open_multipart('bras/create') ?> <label for="title">Title</label> <input type="input" name="title" /><br /> </form> <?php echo form_open_multipart('bras/do_upload') ?> <input type="file" name="userfile" size="20" /><br /> </form> <?php echo form_open_multipart('bras/create') ?> <label for="content">content</label> <textarea name="content"></textarea><br /> <label for="price">Price</label> <input type="input" name="price" /><br /> <input type="submit" name="submit" value="Create Bra item" /> </form>
  4. I think that this might be a zend framework problem, because I made a new webpage with a stylesheet and it works.
  5. No it doesn't but here is my stylesheet.css body{ background-color:#0000CD; } h1{ color: #FF0000; }
  6. Hi I have an undefined variable called todo and I'm not sure how to fix it. I have looked at the tutorials and everything but I'm not sure on how to apply those to my problem. Here is my itemscontroller.php <?php class ItemsController extends Controller { function view($id = null,$name = null) { $this->set('title',$name.' - My Todo List App'); $this->set('todo',$this->Item->select($id)); } function viewall() { $this->set('title','All Items - My Todo List App'); $this->set('todo',$this->Item->selectAll()); } function add() { $todo = $_POST['todo']; $this->set('title','Success - My Todo List App'); $this->set('todo',$this->Item->query('insert into items (item_name) values (\''.mysql_real_escape_string($todo).'\')')); } function delete($id = null) { $this->set('title','Success - My Todo List App'); $this->set('todo',$this->Item->query('delete from items where id = \''.mysql_real_escape_string($id).'\'')); } } and this is my viewall.php where the error is showing up <form action="../items/add" method="post"> <input type="text" value="I have to..." onclick="this.value=''" name="todo"> <input type="submit" value="add"> </form> <br/><br/> <?php $number = 0?> <?php foreach ($todo as $todoitem):?> <a class="big" href="../items/view/<?php echo $todoitem['Item']['id']?>/<?php echo strtolower(str_replace(" ","-",$todoitem['Item']['item_name']))?>"> <span class="item"> <?php echo ++$number?> <?php echo $todoitem['Item']['item_name']?> </span> </a><br/> <?php endforeach?>
  7. I also have layout.phtml <?php echo $this->doctype(); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <?php echo $this->headTitle() ?> <?php echo $this->headLink() ?> <?php echo $this->headScript() ?> </head> <body> <?php echo $this->layout()->content ?> </body> </html> other then that, it's all I have for now.
  8. In my IndexController.php I have class IndexController extends Zend_Controller_Action { public function indexAction() { $this->view->message = 'This is my new Zend Framework project!'; } } and in my index.php I have <h1>Hello World</h1> <?php echo $this->message ?>
  9. Hi I don't know if this is the right place, but I'm using a zend framework and I have wamp installed. My problem is that when I use home.phtml and I try to view it through the localhost all I get is the php coding not the actual content that I wanted. For example <h1>Hello World</h1> <?php echo $this->message ?> And what I get is Hello World message ?> I don't actualy get the correct thing which would How do I fix this? Thank you
  10. Hi I'm using a zend framework with wamp installed. When I try using $this->message for example I get this error: Fatal error: Using $this when not in object context in C:\wamp\www\myproject\application\views\scripts\index\index.php on line 2 How do I solve this? Thank you
  11. It looks fine to me. This is what's on the page source <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Voluptous Decedants</title> <link rel="stylesheet" type="text/css" href="stylesheet.css" /> </head> <body> <h1>home</h1> </body> </html>
  12. Originally my page has a white background and the heading is black. So I wanted the background to be Blue and the heading to be red. But I don't get the colors that I want, it stays the same.
  13. Maybe this will help I'm using zend framework
  14. Nothing happens, I don't even get any errors.
  15. Hi I'm trying to link my css with my webpage but for some reason it's not working and I don't understand why because everything is right. this is the link <link rel="stylesheet" type="text/css" href="stylesheet.css" />
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.