Jump to content

Raj

Members
  • Posts

    18
  • Joined

  • Last visited

Recent Profile Visitors

1,429 profile views

Raj's Achievements

Jr. Member

Jr. Member (3/6)

0

Reputation

  1. Agree with you mate. I have already started going through the doc section once again, hopefully this time I will get the right essence. ?
  2. I can understand Soma, but thank you for your guidance...probably I missed to read through the Docs section properly, let me redo ?
  3. Sure Soma, let me try that ? with re to "You can't call a .php in templates folder, it would have to be somewhere in the webroot." not sure if I am doing it the correct way...all my PHP files are actually residing in site/templates folder, after saving them in this folder I add them as template using the Admin page and access them...and most of my validation pages are called by ajax method defined in custom JS files... I am actually very new to CMS and PHP; learning on my own with abundant help from this forum and Google ? If it doesn't take much time or there is already a page on this, can you help me understand the best way to build a custom site in processwire with custom styles and JS...mainly around where do I place my custom php files...how to utilize processwire to it's capactiy.
  4. Hello Soma, Input field is there in the html form...here is the code , please see after <span> field in the below code -> Could you help guide what you meant by "Why don't you just do it using a real page?" please? <label class="w3-button w3-blue-gray w3-border w3-border-green w3-round-large w3-wide w3-bar uploadimg" style="font-weight:bolder;"><span><i class="fa fa-cloud-upload fa-lg w3-left">&nbsp;|</i></span>Upload Avatar<input type="file" id="upload" accept="image/*" class="avatar"></label>
  5. This is the code that is responsible for invoking the AJAX call. <?php namespace ProcessWire; $session = wire('session'); ?> <span class="w3-col m5"> <div id="upload_img" class="w3-margin w3-border-teal w3-round w3-opacity-min w3-display-container" style="border-style: groove;"> <!--<i class="fa fa-edit w3-xxxlarge w3-hover-red w3-round-large w3-display-bottomright" style="font-weight:bolder;"></i>--> </div> <div class="w3-margin"> <label class="w3-button w3-blue-gray w3-border w3-border-green w3-round-large w3-wide w3-bar uploadimg" style="font-weight:bolder;"><span><i class="fa fa-cloud-upload fa-lg w3-left">&nbsp;|</i></span>Upload Avatar<input type="file" id="upload" accept="image/*" class="avatar"></label> <!--<a class="w3-button w3-blue-gray w3-border w3-border-green w3-round-large w3-wide w3-bar actionUpload"><span><i class="fa fa-cloud-upload fa-lg w3-left">&nbsp;|</i>Change Avatar</span><input type="file" id="upload" value="Choose Image" accept="image/*"></a>--> <button class="w3-button w3-blue-gray w3-border w3-border-green w3-round-large w3-wide w3-bar actionDone" style="font-weight:bolder;"><i class="fa fa-check-circle-o fa-lg w3-left">&nbsp;|</i>Done</button> </div> </span> and this is the AJAX query which is responsible for calling the upload.php page $('#upload').on('change', function () { var reader = new FileReader(); reader.onload = function (e) { $uploadCrop.croppie('bind', { url: e.target.result }).then(function(){ console.log('jQuery bind complete'); }); $('.actionDone').toggle(); $('.uploadimg').toggle(); } reader.readAsDataURL(this.files[0]); }); $('.actionDone').on('click', function (ev) { $('.actionDone').toggle(); $('.uploadimg').toggle(); $uploadCrop.croppie('result', { type: 'canvas', size: 'viewport' }).then(function (response) { $.ajax({ url: '/site/templates/upload.php', type: "POST", data: {"image":response}, success: function (data) { if (data == 'Cropped image uploaded successfully') { html = '<img src="' + response + '" id="img_resp" />'; $("#upload_img").html(html); } else { $("body").append("<div class='upload-error'>" + data + "</div>"); } } }); }); }); Finally this is code in upload.php file that is responsible for uploading the image. <?php namespace ProcessWire; error_reporting(E_ALL); ini_set('display_errors', 1); ob_start(); require_once('/var/www/rajibde/index.php'); ob_end_clean(); $input = wire('input'); $sanitizer = wire('sanitizer'); $config = wire('config'); $session = wire('session'); $upload_path = $config->paths->assets . 'avatar/'; chmod($upload_path, 0777); if ($input->post && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { $user = $session->get('memberName'); $img = $input->post->image; $log->message("image ->" . $img); list($type, $img) = explode(';', $img); list(, $img) = explode(',', $img); list($type,) = explode('/',$type); $img = base64_decode($img); //$img = implode($img,'.',$type); $img = $img . '.' . $type; $log->message("IMG TYPE ->" . $img); $f = new WireUpload($img); $f->setMaxFiles(1); $f->setMaxFileSize(2*1024*1024); $f->setOverwrite(true); $f->setDestinationPath($upload_path); $f->setValidExtensions(array('jpg', 'jpeg', 'png', 'gif')); if(!is_dir($upload_path)) { if(!wireMkdir($upload_path)) throw new WireException("No upload path!"); } $files = $f->execute(); if ($f->getErrors()) { foreach($files as $filename) unlink($upload_path . $filename); foreach($f->getErrors() as $e) echo $e; } else { $log->message("1 ->" . $_FILES); //Save the photo to the avatar field $u = $users->get($user->id); $log->message("2 ->" . $u); $u->of(false); $u->avatar = $upload_path . $files[0]; $log->message("3 ->" . $u->avatar); $u->save(); $u->of(true); unlink($upload_path . $files[0]); print 'Cropped image uploaded successfully'; } } else { echo '<div class="w3-row-padding w3-wide w3-text-red w3-text-jumbo"><strong>Unauthorised access. Your access to this site might be permanently blocked if tresspassing continues</strong></div>'; die(); } ?>
  6. @ryan could please help me on this. I am stuck here and not able to move forward even after spending hours together to understand what and where it is going wrong.
  7. Path is getting populated and stored in DB but the file name and extension is missing in DB. Even the image file doesn't get stored in the upload location -> site/assets/avatar. ? And I am not able to figure out why it is not saving the image
  8. Yes, only with the upload location but the file name and extension is missing.... In other words "echo files[0]" doesn't yield any value.
  9. Can someone please help me, I am using the same code as mentioned above with some additional security check; even though the result is successful the image file is not being stored in the avatar folder within site/asset. <?php namespace ProcessWire; error_reporting(E_ALL); ini_set('display_errors', 1); ob_start(); require_once('/var/www/rajibde/index.php'); ob_end_clean(); $input = wire('input'); $sanitizer = wire('sanitizer'); $config = wire('config'); $session = wire('session'); $upload_path = $config->paths->assets . 'avatar/'; chmod($upload_path, 0777); if ($input->post && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { $user = $session->get('memberName'); $img = $input->post->image; list($type, $img) = explode(';', $img); list(, $img) = explode(',', $img); list($type,) = explode('/',$type); $img = base64_decode($img); //$img = implode($img,'.',$type); $img = $img . '.' . $type; //print_r('Successful' . $img); $f = new WireUpload($img); $f->setMaxFiles(1); $f->setMaxFileSize(1*1024*1024); $f->setOverwrite(true); $f->setDestinationPath($upload_path); $f->setValidExtensions(array('jpg', 'jpeg', 'png', 'gif')); if(!is_dir($upload_path)) { if(!wireMkdir($upload_path)) throw new WireException("No upload path!"); } $files = $f->execute(); echo $files[0]; if ($f->getErrors()) { foreach($files as $filename) @unlink($upload_path . $filename); foreach($f->getErrors() as $e) echo $e; } else { //Save the photo to the avatar field $u = $users->get($user->id); $u->of(false); $u->avatar = $upload_path . $files[0]; //echo $u->avatar; $u->save(); $u->of(true); @unlink($upload_path . $files[0]); print_r('Successful' . $img . $files[0]); echo 'Cropped image uploaded successfully.'; } } else { echo '<div class="w3-row-padding w3-wide w3-text-red w3-text-jumbo"><strong>Unauthorised access. Your access to this site might be permanently blocked if tresspassing continues</strong></div>'; die(); } ?>
  10. Dear All, Request your assistance on building the Sign In form, my query might be very silly but I am trying from past few days to get this working. Basically, I am calling the LoginPersist module to log the user in, to utilize the persistent cookie setting; however, once logged in I want to check the user role and redirect them to respective page accordingly. I am stuck in referring the $user instance from LoginPersist module to perform this check. Please help... Login page ------------------------ <?php namespace ProcessWire; ob_start(); require_once('/var/www/bluemine/index.php'); require("./ip.php"); ob_end_clean(); if($session->CSRF->hasValidToken()) { $input = wire('input'); $sanitizer = wire('sanitizer'); $config = wire('config'); $session = wire('session'); $ip = ip2long($ipaddress); if ($input->post && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { $rte = array(); $remme = $input->post->rememberme; if($remme == 'rememberme'){ $persist = wire('modules')->get('LoginPersist')->persist(); $uname = $persist->$session->$name; $rte['msg4'] = 'persistent'; if ($uname->hasRole('superuser')) { $rte['msg'] = 'admin'; $rte['route'] = '/admin/access/users/'; } elseif ($uname->hasRole('mine')) { $rte['msg'] = 'member'; $rte['route'] = '/phpconf/'; } else { $rte['msg'] = 'Not Activated'; } } else { if(!$user->isLoggedin()) { $uname = $sanitizer->username($input->post->lname); $pass = $input->post->lpswd; $rte['msg4'] = 'non_persistent'; try { $u = $session->login($uname, $pass); if($u && $u->id) { if ($u->hasRole('superuser')) { //$session->redirect('/admin/access/users/'); $rte['msg'] = 'admin'; $rte['route'] = '/admin/access/users/'; } elseif ($u->hasRole('mine')) { //$session->redirect('/profile/'); $rte['msg'] = 'member'; $rte['route'] = '/phpconf/'; } else { $rte['msg'] = 'Not Activated'; } } else { $rte['msg'] = 'Login Failed'; $errors .= "Login failed."; } echo json_encode($rte); } catch(WireException $e){ // in case of multiple false login (throttle login) $errors .= $e->getMessage(); // get the error message } } else { $rte['msg'] = 'You are already logged in.'; echo json_encode($rte); die(); } } } else { echo "<font color=red><strong>Unauthorised access. Your access to this site might be permanently blocked if tresspassing continues</strong></font>"; die(); } } else { //throw new WireException('CSRF check failed!'); $rte['msg'] = 'Tresspassing'; $rte['msg1'] = '<div class="w3-panel w3-red w3-card-4 w3-display-middle"><p class="w3-jumbo w3-red"><strong><h1>Forgery Attempt:</h1> <h3>The site has closed the connection. This occurs due to abrupt network disruption or in an event of hackers trying to steal information.</h3> <h2><small>Return to <a href="./">Homepage</a></small></h2></strong></p>'; echo json_encode($rte); die(); } ?> AJAX post from Login Page... $.ajax({ type: 'POST', url: url, data: postData, dataType: 'json', success: function (data) { if(data.msg == "member") { window.location.href = data.route; } else if(data.msg == "admin") { window.location.href = data.route; } else if(data.msg == "Not Activated") { $('#errmsg').css('display','block'); $('#loginerror').html('You are yet to activate the account. Please follow the link sent via email during registration for activation.'); document.getElementById('limgcaptcha').src="/site/templates/lcaptcha.php?id=" +((new Date()).getTime()); $('#loginform :input').attr('disabled', false); $('#show_pswd').attr('disabled',false); document.getElementById('lname').value = ""; document.getElementById('lpswd').value = ""; document.getElementById('lsec').value = ""; $("#cookie").prop('checked',false ); } else if(data.msg == "Login Failed") { $('#errmsg').css('display','block'); $('#loginerror').html('Login Failed. Please try again, or use the forgot password link below.'); document.getElementById('limgcaptcha').src="/site/templates/lcaptcha.php?id=" +((new Date()).getTime()); $('#loginform :input').attr('disabled', false); $('#show_pswd').attr('disabled',false); document.getElementById('lname').value = ""; document.getElementById('lpswd').value = ""; document.getElementById('lsec').value = ""; $("#cookie").prop('checked',false ); } else if(data.msg == "Tresspassing") { $('#main').html(data.msg1); //$('#errmsg').css('display','block'); //$('#loginerror').html(data.msg1); } } }); }); I know this code if lot more repetitive and can be cut short but I am learning this whole thing (PHP Language -> Processwire, CSS and JavaScript) of my own, hence Site Moderator / Members valuable feedback, above and beyond the exact issue is very much welcomed.
  11. Thank you guys....sorry for the late response, was held up with some stuffs. require_once('...') did the trick finally...had to key in the complete URL - probably miss-configuration of php.ini file.... Now while I have changed to WireMail I am getting the error "Error: Uncaught exception 'ProcessWire\WireException' with message 'Method WireMailSmtp::IsHTML does not exist or is not callable in this context" What does this mean?
  12. Thank you 3fingers for the response, my file is placed under site/templates folder...I even tried adding the require once statement but it did not work.
  13. When I do this , "$input = wire('input');" I get the error - Call to undefined function ProcessWire\wire()... What am I missing? I completely agree with you Kongondo and I am doing that simultaneously...actually I am a no coder, long ago I did my software engg. but could not get any job in this line....so forgot all those concepts, trying to recall mystic memories....The site that I am trying to setup now is just out of my passion for networking and coding...hope I can make something good for my family and friends...
  14. I changed this "$input = wire('input');" to "$input = $this->wire('input');"; however, still get the error "Using $this when not in object context...."
  15. Thank you Kongondo. I am still stuck with this...not able to get my head around, not sure where I am failing. Would you mind helping my out here with the code mentioned initially. How do I make those variables an instance of wire?
×
×
  • Create New...