Jump to content

M.O.S. Studios

Members
  • Posts

    300
  • Joined

  • Last visited

Everything posted by M.O.S. Studios

  1. Hey guys, I have a script I’m working on, and I was curious if I can do the following: 1. user clicks button on browser, that sends a request to the server using ajax 2. the server creates a zip file and stores it in php://memory 3. the browser get the needed information to initiate a download of the zip file. can this be done? I suspect I have to physically save the file on the server, and delete it after; which I would like to avoid
  2. Hey everyone, I am trying to take information from a DB and convert it into a string that has CSV values. some of the values have commas and double quotes, which messes up the end product. is there a way to escape the string so it is rfc 4180 compliant? I don’t want to create a file. I know I can use str_putcsv along with php://temp; but ideally I wouldn’t do that. Mostly because my shared hosting has issues php://temp thanks in advance!
  3. I might have worded it wrong. I want it so that if any of those three methods have an exception, it will bubble up to the try/except in the _construct method. for example: class myclass{ public function func1(){ //line of code that creates fatal error } function __contruct(){ try(){ $this->func1(); }catch(Exception $e){ echo "found a error"; } } } the above will work only if the exception is thorwn within the scope of func1(). if func1() calls an external function that throws an exception, it wont catch it. It doesn't "bubble up". if I change it to: class myclass{ public function func1(){ try(){ buggyFunc(); }catch(Exception $e){ throw new Exception($e); } } function __contruct(){ try(){ $this->func1(); }catch(Exception $e){ echo "found an error"; } } } this works. The problem is, if you look back to my original example: I don't want any subsequent functions to run if the previous function had an error. At the same time, I don't want to a script filled with "try/catch/throw" commands
  4. Hey Everyone, Odd question. I am working with a class that runs methods when a new instance is created. Is there a way to catch any errors thrown within the methods? Here is the code: function __construct(){ try{ $this->val1 = $this->func1; $this->val1 = $this->func2; $this->val1 = $this->func3; }catch(Exception $e){ $this->notes($e); $this->errors = true; } } Ideally, if method "func1" throws an error at anypoint within it, then it will be caught by "catch" in _construct. Is this possible, or do I need to add "try/catch" to each method?
  5. This looks awesome! Probably just what I need. stupid question: I’m on shared hosting with no terminal. So that means no composer. Do you think I can install this another way?
  6. Hey Everyone, I am working on a short script that transfers information from one source to another. Both have a ReST api. I was curious if anyone knew any resources that can make that easier. Ideally, it would be a php file I can use to make an object for each API? Any ideas?
  7. function spamTest($header){ $output_array = preg_grep('/^(X-Spam-Score:)\s([-+]?\d{1,3}\.\d)?/i', explode("\n", $header)); list($xSpamScore, $score) = explode(": ", $output_array[array_key_first($output_array)]); return ($score < 5); } I ran the email header into this and it seems to work.
  8. Ok! So I have been doing the following research: I watched this video to understand how these protocols work I took a look at the headers you posted I sent my php script some real, and spoofed emails I now have a better understanding of what you were explaining to me. My email server does all the checking for me and puts the results into the header of the email. All I need to do is create a php script that checks the headers to see if it passed. Thus the regex code. Is that correct?
  9. Is it really just regex? That’s way easier than I thought it was going to be. I assumed I needed to grab some kind of address, then verify it using a service. thanks! I will look more into this andmuodate the post
  10. Sorry, I meant can you recommend a good php library that can verify its not a spoof once I get the headers.
  11. Yeah, That's so amazing to hear. Do you have any libraries you can recommend? When I look up this topic, the majority of stuff is about validating the content of an outgoing email, as opposed to what I am looking for.
  12. Thanks for the reply. That's unfortunate. I am not using it as a client e-mail validator. Here in Canada, we use E-transfer for payments. Essentially, people can send you money all they need to know is your email. It's pretty awesome. When you receive payment; you get an email from Interac (it's like Visa, but only for debit transactions). I plan to have a dedicated email for E-transfers and pipe all incoming e-mails to a PHP script. When Interact sends a confirmation email; the php program will automatically mark the order as paid. My concern is that someone could easily spoof an email like that. So I was hoping there was a way to validate the email
  13. Hey everyone, I am piping email to a php scripts. I am doing this to automate some processes. I would like to program the script to check the email of the sender, and delete any that are not on an approved list. Is there a way to validate the email isn't spoofed? I’d like to make sure the email is actually from the domain they claim to be from Thanks in advance!
  14. Hey Everyone, I am hoping to find a framework that can easily do the following: 1. Take the information I feed it, and turn it into a simple form that can store and validate entries into a MYSQL Database 2. Use entries from one table as drop-down options for another 3. Allow me to search the database and display them easily. I originally used Google Sheets for it, but I'm finding that is going to be a lot of work. I attached screenshots of the documents to give an idea of what the functionality is going to be I know none of this is hard to do. I don't want to go through the trouble of making a front-end, and troubleshooting if there is a faster way.
  15. this worked exactly as needed!
  16. Ah, so if I log in on one page, and make a Ajax call to another page; it should work? Even if the link is an absolute address like https://myodomain/page.php opposed to page.php?
  17. Fancy isn't important as I am the only one using it. However easy is ideal. I was thinking of using htaccess, htpasswd, .htaccess. I have never used those before, but I think they will be pretty simple to set up. My only concern is that I use Ajax to reference other pages, and I am worry that will interfere
  18. Hey Everyone, I own a business (unrelated to programming). To make my life easier I made some php apps that automate some of the paperwork I have to do. Does any one know a good framework that will allow me to put these behind a username and password? ideally, it would be something really simple to use. I want to avoid having to learn all the intricacies of something like drupal. In my mind, I picture a software that I install, put all my files in one directory, and those files now can only be accessed though this software . any thoughts?
  19. Figured it out. Here is my round about way to take a CSV file, and visualize it as a table. <?php require('fpdf.php'); $file = file.csv'; function near5($v){ return round($v * 2) / 2; } function content($file){ $header = array(); if (($handle = fopen($file, "r")) !== FALSE){ $body = array(); $header = fgetcsv($handle); $header[0] = 'Category/Weight(Lbs)'; while (($data = fgetcsv($handle)) !== FALSE){ $body[] = $data; } fclose($handle); } return array($header, $body); } class PDF extends FPDF{ // Simple table function BasicTable($header, $data, $kcal){ // Header $first = 30; foreach($header as $col){ $v = is_numeric($col) ? round(($col*2.2),1) : $col; $this->Cell($first,7,$v,1,0,'C'); $first = 10; } $this->Ln(); // Data foreach($data as $row){ $first = 30; foreach($row as $col){ $v = (is_numeric($col)) ? near5($col/$kcal) : $col; $this->Cell($first,7,$v,1,0,'C'); $first = 10; } $this->Ln(); } } } // Column headings content($file); list($header, $row) = content($file); // Data loading $pdf = new PDF(); $pdf->SetFont('Arial','',5); $pdf->AddPage(); $pdf->BasicTable($header,$row, $kcal); $output = $pdf->Output('S'); $im = new imagick(); $im->setResolution(300, 300); $im->readImageBlob($output); $im->setImageFormat('png'); $im->setImageCompression(imagick::COMPRESSION_JPEG); $im->setImageCompressionQuality(100); $im->borderImage("#ffffff", 20, 20); $im->trimImage(0.3); $im->setImagePage($im->getImageWidth(), $im->getImageHeight(), 0, 0); header("Content-Type: image/" . $im->getImageFormat()); echo $im->getImageBlob(); $im->clear(); $im->destroy(); ?>
  20. So I was working on this for a bit, and I found a round about way to do it. It requires FPDF, and Imagick. <?php require('fpdf.php'); $file = 'file.CSV'; $kcal = 2000 / 1000; function near5($v){ return round($v * 2) / 2; } function content($file){ $header = array(); if (($handle = fopen($file, "r")) !== FALSE){ $body = array(); $header = fgetcsv($handle); $header[0] = 'Category/Weight(Lbs)'; $w = 20 + (count($header)*10); $h = 7; while (($data = fgetcsv($handle)) !== FALSE){ $body[] = $data; $h += 7; } fclose($handle); } return array($header, $body, $h, $w); } class PDF extends FPDF{ // Simple table function BasicTable($header, $data, $kcal){ // Header $first = 30; foreach($header as $col){ $v = is_numeric($col) ? round(($col*2.2),1) : $col; $this->Cell($first,7,$v,1,0,'C'); $first = 10; } $this->Ln(); // Data foreach($data as $row){ $first = 30; foreach($row as $col){ $v = is_numeric($col) ? near5($col/$kcal) : $col; $this->Cell($first,7,$v,1,0,'C'); $first = 10; } $this->Ln(); } } } // Column headings content($file); list($header, $row, $h, $w) = content($file); // Data loading $pdf = new PDF(); $pdf->SetFont('Arial','',5); $pdf->AddPage(); $pdf->BasicTable($header,$row, $kcal); $output = $pdf->Output('f.pdf','F'); $imagick = new Imagick(); $imagick->readImage('f.pdf'); $imagick->setImageCompressionQuality(100); $imagick->setResolution($w*500,$h*500); $imagick->borderImage("#ffffff", 20, 20); $imagick->trimImage(0.3); $imagick->setImagePage($imagick->getImageWidth(), $imagick->getImageHeight(), 0, 0); $imagick->setImageFormat("png"); header("Content-Type: image/" . $imagick->getImageFormat()); echo $imagick->getImageBlob(); unlink('f.pdf'); two problems and this would work perfectly. 1. The resolution is awful. I tried messing around with the settings; I couldn't figure it out. Any ideas? 2. I'd prefer to have it where it doesn't save the PDF file. Is there a way I can send it to imagick without saving the file? Here is the CSV File heaading,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13,h14 Row1, 2,3,4,5,6,7,8,9,10,11,12,13,14 another,12,13,14,15,16,17,18,19,110,111,112,113,114
  21. I haven't had time until now to work on this project. I am going to take a crack at it now. these images are going to be accessed by a design program that can grab photos from a url. Since there is no browser directly involved, I don't think javascript would work. Thanks for the link! I will take a look at the library
  22. At first glance this is what I am looking for. yeah, I wanted to arrange the data as a chart, like how it would be displayed if it was opened in excel. I am going to see if I can work with what you sent me
  23. Php has lots of libraries and functions to turn text into an image. I want to take a CSV file, and use the values to create a JPG image Here is an example of what I am looking for. This requires Java, which I don’t have
  24. I ended up starting over and it worked :/. Don’t know what I did differently
  25. Hey everyone! I’m convert a CSV file into a Jpg file using php. so, the script would take the information from the CSV file, and create a visual version that can be viewed on program that displays JPG. anyone of a script that does that? i was thinking of making it from scratch, but thought I might be reinventing the wheel
×
×
  • 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.