|
stoops posted:If I have this working correctly, should i still rename the file uploaded? As revmoo said, yes, rename the file to avoid collisions. If you're paranoid (like me!) you can do something like this: code:
Use the database to keep a record of the original filename, the new hash path, etc.. As the file isn't at a browsable location, you don't really have a risk of it being a server-executable script anymore, so that's nice. But you do need to serve it back to the user with the original filename, so you can do something like: code:
|
# ? Dec 4, 2015 00:15 |
|
|
# ? Jun 3, 2024 06:39 |
|
poxin posted:I have an array that I am pulling from a (crap)API It sounds like you've got bigger problems if you can't even echo stuff out. Are you sure you don't have a syntax or other error and you've just got errors suppressed? Try this after your API call: code:
As the for rest of your problem, here's the quickest brute-force method I could think of; code:
|
# ? Dec 4, 2015 00:32 |
|
v1nce posted:If you don't see the error, then something's fucky. If you do, remove trigger_error and then try the rest of your code. print_r($output); worked just fine using the API to produce the array. I was having problems trying to get any data out of it and format it the way I need. I think I see what your code is doing, thank you very much for that! It's looking pretty close to what I'm attempting to do with it. Edit: Quick question, what would be the correct syntax for doing an operation under $map code:
poxin fucked around with this message at 00:58 on Dec 4, 2015 |
# ? Dec 4, 2015 00:43 |
|
v1nce posted:As the file isn't at a browsable location, you don't really have a risk of it being a server-executable script anymore, so that's nice. But you do need to serve it back to the user with the original filename, so you can do something like: And could also use Cake's Response object to serve up file downloads. http://book.cakephp.org/2.0/en/controllers/request-response.html#sending-files I've used this concept to create a download controller method along with routing to serve non-public files as pretty URLs in <a href> links.
|
# ? Dec 4, 2015 01:00 |
|
You want to run a function to modify the format of the data? that's a bit more complicated. The map is just saying A=>B or A becomes B. The foreach does the legwork. Here's a more exciting example of a mapper that uses anonymous functions to process each row of data. code:
|
# ? Dec 4, 2015 01:18 |
|
v1nce posted:You don't really want to go beyond that in procedural code. If it needs to be more advanced then you should introduce some OOP into your life. You are my hero, actually learning a hell of lot from this. While being able to format the data is awesome I was looking to do something under data mapping where I have "space" and "total_space" in an attempt to divide those two in order to get a percentage value. code:
|
# ? Dec 4, 2015 20:57 |
|
I have an obvious question, if Facebook are so smart and the PHP developers so dumb how is PHP 7 significantly faster than HHVM? Am I answering my owner question in that they are gaming the benchmarks by using new features that are only in PHP 7?
|
# ? Dec 5, 2015 00:47 |
|
PHP 7 is only faster than HHVM for certain operations. Overall, PHP 7 is still slightly slower than HHVM in most non-artificial benchmarks, but there's no longer a huge performance gulf between the two. Also, it's only a few members of internals that are dumb. Check out the last few entrys on NikiC's blog: https://nikic.github.io/
|
# ? Dec 5, 2015 00:51 |
|
poxin posted:You are my hero, actually learning a hell of lot from this. While being able to format the data is awesome I was looking to do something under data mapping where I have "space" and "total_space" in an attempt to divide those two in order to get a percentage value. Think I figured this out code:
|
# ? Dec 5, 2015 02:27 |
|
I have this arraycode:
I've tried to convert the month to string but it still shows it as an integer. Any help is appreciated.
|
# ? Dec 11, 2015 19:05 |
|
How did you try converting to string? I would cast. Ie: $month = '11'; echo (string) $month;
|
# ? Dec 11, 2015 19:24 |
|
revmoo posted:How did you try converting to string? That's exactly how I did it and it still showed up exactly as the array I posted. I ended up concatenating a blank space so it can automatically convert it to a string, but I feel what you posted should have worked.
|
# ? Dec 11, 2015 19:32 |
|
Probably has something to do with that the other two months are casted to strings to preserve the leading zero. Start your search with the part of code that does that.
|
# ? Dec 11, 2015 19:48 |
|
Dollars to donuts it's happening because of implicit octal conversion. What happens when there's, say, '01' through '07'? That'd then break on '08' and '09', which aren't valid when converting octal to integer. 10 and 11 bypass it, no leading zero.
|
# ? Dec 12, 2015 07:51 |
|
McGlockenshire posted:implicit octal conversion
|
# ? Dec 14, 2015 15:24 |
|
I have an intranet server with many folders. Each folder is its own site. Each site folder has its own instance of cakephp installed. Some sites have an older version of cake, others have a new version. To get to any site it would be something like: http://myserver.com/site1 http://myserver.com/site2 http://myserver.com/site3 and so on.... Each site has its own login/database and they all work fine. My problem comes with the browser, saving passwords. When I try to save my password for a particular site, it saves it as: http://myserver.com/ I'm not sure what to do, either on cakephp or on the folder (maybe htaccess?), to make it known that the folder is a website and should be saved as http://myserver.com/site3 or whatever. Hope what I wrote makes sense. Any help is appreciated. I would google this, but I'm not entirely sure the search terms.
|
# ? Dec 28, 2015 21:43 |
|
You're looking for cookie path. If you set a cookies path to "/" it's available across the entire domain. If you set it to "/derp/" then it's only available to pages under derp, such as "/derp/herp". You can set this globally (i think) in Cake3 and Cake2.
|
# ? Dec 28, 2015 23:31 |
|
v1nce posted:You're looking for cookie path. Thanks, but I may have constructed my question wrong. To me, a cookie means to save a user from having to log in again. (they are just automatically logged in) What I'm trying to do is let the browser use its "autocomplete form". Usually when I go to any website with a login, I click on the textbox and usernames pop up for that site, then when I click on one of them, the password pops in the password field and then I can click submit to login. The problem I'm having is that all the site folders I have, for some reason, aren't saved to the Browser as http://myserver.com/site2. only as http://myserver.com/ In my case, I use the same username for every site, but I use different passwords for each site. So when i go to site3, and i click for the autocomplete, it will give me the password for whatever last site i logged in instead of the password for this specific site. Maybe this is not a php question? Basically, all the folders on my server are websites, but the browser autocomplete thinks its all one domain.
|
# ? Dec 29, 2015 16:57 |
|
stoops posted:Thanks, but I may have constructed my question wrong. Yeah, this is a problem with your browser just saving the login for the entire domain. You can try a third party tool such as 1password. I have had better luck doing it that way. Our company intranet lets us edit clients and has a field labeled 'email address', so for awhile every time I edited a client the browser would just go ahead and auto fill that email address with my personal email address and I didn't notice. Then for several days I was getting all these client notifications and clients started bitching to customer service that our system was all broken and poo poo. So yeah... there ya go, autocomplete is cool in some ways, but other times it sucks. Long term though, aside from the subfolder password issues, its often beneficial to setup a separate domain for each site. So you would have site1.myserver.com, site2.myserver.com etc. This becomes a huge deal if it ever comes time to say migrate a specific site to a new version of php on a new server, or if you need to split up sites on different servers due to server load. You can also do poo poo at the router with the domain if you need to. This will resolve any issues with cookies, and as a side benefit this would also fix the issue you are having with the passwords. Its good practice to do that with the database server as well, instead of using localhost or https://www.myserver.com use db1.myserver.com or some poo poo.
|
# ? Dec 29, 2015 20:33 |
|
Is there a modern, free solution to convert some HTML/CSS to a PDF through PHP? I found a SO answer but the top answer is from 2009. It's not my place in this organization to propose installing node.js/phantom to do it (which is the only way I've handled this problem so far).
|
# ? Jan 8, 2016 22:28 |
|
hedgecore posted:Is there a modern, free solution to convert some HTML/CSS to a PDF through PHP? There's a few libraries https://packagist.org/packages/dompdf/dompdf that are common. However, if this is for a company tell them to stop being such cheap asses and use DocRaptor - https://docraptor.com/
|
# ? Jan 8, 2016 22:39 |
|
Laravel is about to make me lose my poo poo. I've got these two Eloquent models, Thing and ThingBag. Thing has a BelongsTo relationship with ThingBag, and ThingBag has a HasMany relationship with Thing. So I iterate over the Things in the ThingBag and do some work with them. I may need to remove a Thing from the ThingBag, which I do with: code:
code:
This has got to be a common enough problem that I've just overlooked something in Laravel's vast, comprehensive documentation, right?
|
# ? Jan 8, 2016 23:33 |
|
hedgecore posted:Is there a modern, free solution to convert some HTML/CSS to a PDF through PHP? Try mPDF. https://github.com/mpdf/mpdf
|
# ? Jan 8, 2016 23:59 |
|
Wkhtmltopdf is rad. Also there's a composer plg
|
# ? Jan 9, 2016 03:01 |
|
Tiny Bug Child posted:Laravel is about to make me lose my poo poo. I've got these two Eloquent models, Thing and ThingBag. Thing has a BelongsTo relationship with ThingBag, and ThingBag has a HasMany relationship with Thing. You can call $thingbag->load('things') to refresh the model's things relationship from the database.
|
# ? Jan 9, 2016 03:36 |
|
revmoo posted:Wkhtmltopdf is rad. Also there's a composer plg If you're working with JavaScript, you can use PhantomJS to headlessly generate a PDF from a page, which seems to be the "modern" way to handle the problem.
|
# ? Jan 9, 2016 03:52 |
|
Depressing Box posted:You can call $thingbag->load('things') to refresh the model's things relationship from the database. Yeah, but I'd prefer not to hit the database again for something I already know.
|
# ? Jan 9, 2016 04:51 |
|
Tiny Bug Child posted:Yeah, but I'd prefer not to hit the database again for something I already know. Ok, then instead of assigning directly to $thingbag->things, try: PHP code:
|
# ? Jan 9, 2016 06:31 |
|
Depressing Box posted:Ok, then instead of assigning directly to $thingbag->things, try: That's exactly what I needed, thanks a lot.
|
# ? Jan 9, 2016 06:50 |
|
Thanks for the recommendations. I'll try those out. It's a fairly simple layout so hopefully that will play to my advantage.
|
# ? Jan 9, 2016 19:47 |
|
I have alot of images inaccessible from the outside (I put them outside of webroot). But once you log in and are authenticated, I use cakephp's response method for the pictures to show up. This works fine for a little amount of pictures, but now, as I'm hitting about 120 pics a page, a lot of the images aren't coming out (some images come out sporadically). I have a feeling it's my image request, that i'm doing wrong. in the view code:
code:
GET http://domain/plots/get_file/view/image1.gif [HTTP/1.1 302 Found 3718ms] GET http://domain/plots/get_file/view/image2.gif [HTTP/1.1 302 Found 3754ms] but when an image doesnt show up, I get GET http://domain/ [HTTP/1.1 200 OK 856ms] Is it that i'm doing it wrong in Cake, or that the browser can't handle showing that many images? Each image is about 8k, 792*612 but i default the width and height to 200*155 Any help is appreciated. I can't really divulge the link, but if anyone wants to look at it to see what I mean, I can PM you.
|
# ? Jan 15, 2016 22:14 |
|
I'm not familiar with cakephp, but if you are sending 120 simultaneous requests that need to be processed by your php framework some of them probably fail because your server is running out of resources. I think simplest, though maybe not the most correct thing would be to include images into the page itself in base64 encoding in the form ofcode:
Forgall fucked around with this message at 22:35 on Jan 15, 2016 |
# ? Jan 15, 2016 22:32 |
|
What do you folks like for a http client library? I have some scripts written using curl and attempted to move them over to Guzzle. It almost seems easier for to just use curl for simple API tasks. I found Httpful which is actually quite nice and will probably use that instead unless there are better suggestions.
|
# ? Jan 30, 2016 17:39 |
|
composer require rmccue/requests
|
# ? Jan 30, 2016 20:26 |
|
LET IT BE KNOWN that Symfony can go and eat a bag of dicks. Never let java programmers near your framework people, things can only go wrong.
|
# ? Feb 2, 2016 06:07 |
|
All well designed frameworks end up looking like that. Once you realize what stupid architecture you need in order to get a reasonable design that is also testable, ending up with AbstractGenericRepositoryFactoryImplementations is a given. I've ended up using a bunch of smaller libraries instead of going full framework. It sometimes ends up being more work, but the underlying code and API can be way easier to understand.
|
# ? Feb 2, 2016 06:52 |
|
duck monster posted:LET IT BE KNOWN that Symfony can go and eat a bag of dicks. Never let java programmers near your framework people, things can only go wrong. Hahaha more fool you if you think that the Symfony Bundle standard is the lovely end of the stick. Symfony and Zend are exactly the same in their fat-bitch structure and it's all in an effort to support testing, which they do really quite well.
|
# ? Feb 2, 2016 10:52 |
|
At least it's Laravel, the lobotomized Symfony with only half its documentation that wants you to pay for videos
|
# ? Feb 3, 2016 17:16 |
|
v1nce posted:Hahaha more fool you if you think that the Symfony Bundle standard is the lovely end of the stick. Symfony and Zend are exactly the same in their fat-bitch structure and it's all in an effort to support testing, which they do really quite well. Maybe its a PHPs rather than symfony problem, but frameworks in other languages, notably Django and Rails, seem to have solved these problems and can do full coverage fully mocked testing without all the bureacracy and without ending up in the lobotomized state Laravel is in (Laravel is actually OK imho, its just that its ORM is garbage and it really needs to swap out its shity regexy template thingo for something like Twig or even Smarty. For *small* sites its great.) i dunno, I feel like I''ve spent the past your fighting the framework instead of getting projects out the door.
|
# ? Feb 5, 2016 01:13 |
|
|
# ? Jun 3, 2024 06:39 |
|
I feel the exact opposite with Symfony (and Doctrine to a lesser extent, which I have a love/hate relationship with). It's completely changed how I build apps, and has allowed me to get many high quality, tested, in-depth projects out into production over the past three years.
|
# ? Feb 5, 2016 02:55 |