|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
Guys, how do you get the new filepath of the file that was recently uploaded via php?
$uploaddir = '/gallery/'; $uploadFile = $uploaddir . basename($_FILES['fileToUpload']['tmp_name']);
die(json_encode(array( 'success' => true, 'status' => "File is uploaded successfully. - 8", 'filePath' => $uploadFile )));
but the path I get points to the tmp folder, not the folder and the filename where it was uploaded to.
More info over here. http://stackoverflow.com/questions/27818823/php-getting-the-filepath-of-the-file-after-uploading-to-server
|
I thinkgood programming is something similar to good painting.
You have to have a brain for it and you have to practice technique. No matter how much i practiced for my stupid art aclasses in school, in 12 years i did not produce a single good looking picture. And similar, some people in my university are incapable of producing good code, their brain isnt made for it.
But university CS degrees arent about programming, you learn mostly other stuff and have some basic programming classes. Same as an art degree is probably not painting things all week (i think?).
hey what would you recommend to programm a little 3d video game? i heared c++ is the best for this?
what libaries would i need besides opengl? i would need something to load files with sound, images, 3d models etc. Which SDK can offer all that. I am looking for something that makes life easy. But i want to go the professional way
that totally depends. If you just want to get it over with and design your game and dont care that you cant really tune everything, then Unity or a similar engine. It can also be used in C# for example.
If you are in it for the experience or need something custom, then you need C++ with either directX or openGL.
Also, there are shades between those 2 options, but im not a game programmer so i dont know whats hot right now regarding that.
|
On January 08 2015 09:52 SilverSkyLark wrote:Guys, how do you get the new filepath of the file that was recently uploaded via php? $uploaddir = '/gallery/'; $uploadFile = $uploaddir . basename($_FILES['fileToUpload']['tmp_name']);
die(json_encode(array( 'success' => true, 'status' => "File is uploaded successfully. - 8", 'filePath' => $uploadFile )));
but the path I get points to the tmp folder, not the folder and the filename where it was uploaded to. More info over here. http://stackoverflow.com/questions/27818823/php-getting-the-filepath-of-the-file-after-uploading-to-server
Why do you think it was uploaded to the gallery directory? I'm pretty sure when you upload via php it writes a temp file, if you actually want to put it in a certain directory, you have to move it there. If you never move the file there, its going to still be in the tmp dir.
Edit: From reading your SO post, it looks like you write the file as $_FILES['fileToUpload']['tmp_name'], but according to the comment above the code that you copy and pasted, the real file name is in $_FILES['fileToUpload']['name'].
|
On January 08 2015 10:58 berated- wrote:Why do you think it was uploaded to the gallery directory? I'm pretty sure when you upload via php it writes a temp file, if you actually want to put it in a certain directory, you have to move it there. If you never move the file there, its going to still be in the tmp dir. Edit: From reading your SO post, it looks like you write the file as $_FILES['fileToUpload']['tmp_name'], but according to the comment above the code that you copy and pasted, the real file name is in $_FILES['fileToUpload']['name'].
I actually made it work, but it doesn't make sense to me. What happened was I used basename instead of sha1_file so that the temp filename was kept. I can't seem to make it work using sha1_file.
if (!move_uploaded_file( $_FILES['fileToUpload']['tmp_name'], sprintf('./gallery/%s.%s', basename($_FILES['fileToUpload']['tmp_name']), $ext ) )) { die(json_encode(array( 'success' => false, 'status' => "Failed to move uploaded file. - 7", )));
}
$uploaddir = '/gallery/'; $name = $_FILES["fileToUpload"]["tmp_name"]; $fullPath = sprintf('/gallery/%s.%s', basename($_FILES['fileToUpload']['tmp_name']), $ext );
die(json_encode(array( 'success' => true, 'status' => "File is uploaded successfully. - 8", 'filePath' => "$fullPath" )));
the basenames used to be sha1_file, but I can't seem to make sha1_file work on the 2nd call when I'm assembling the filename.
|
That's because basename takes full path to file as its first argument, not just the name and it returns just the filename, not its path.
$name = $_FILES['fileToUpload']['tmp_name']; $path = '/gallery/';
$filePath = "{$path}{$name}"; // param = "/gallery/yourfile.yourext" $fileName = basename($filePath); // will return file name with extension
// alternate
$filePathArr = pathinfo("{$path}{$name}"); // param = "/gallery/yourfile.yourext"
$fileDir = $filePathArr['dirname']; // "/gallery" $fileNameExt = $filePathArr['basename']; // "yourfile.yourext" - same as basename() $fileName = $filePathArr['filename']; // "yourfile" $fileExt = $filePathArr['extension']; // "yourext"
$filePath = "{$filePathArr['dirname']}/{$filePathArr['basename']}; // "/gallery/yourfile.yourext"
|
On January 08 2015 14:43 Manit0u wrote:That's because basename takes full path to file as its first argument, not just the name and it returns just the filename, not its path. $name = $_FILES['fileToUpload']['tmp_name']; $path = '/gallery/';
$filePath = "{$path}{$name}"; // param = "/gallery/yourfile.yourext" $fileName = basename($filePath); // will return file name with extension
// alternate
$filePathArr = pathinfo("{$path}{$name}"); // param = "/gallery/yourfile.yourext"
$fileDir = $filePathArr['dirname']; // "/gallery" $fileNameExt = $filePathArr['basename']; // "yourfile.yourext" - same as basename() $fileName = $filePathArr['filename']; // "yourfile" $fileExt = $filePathArr['extension']; // "yourext"
$filePath = "{$filePathArr['dirname']}/{$filePathArr['basename']}; // "/gallery/yourfile.yourext"
I see. So how do I use sha1_file instead of basename? I like how the new filename after sha1_file is so long. The filename of the files as they get to the tmp folder seems boring honestly.
|
On January 08 2015 16:45 SilverSkyLark wrote:Show nested quote +On January 08 2015 14:43 Manit0u wrote:That's because basename takes full path to file as its first argument, not just the name and it returns just the filename, not its path. $name = $_FILES['fileToUpload']['tmp_name']; $path = '/gallery/';
$filePath = "{$path}{$name}"; // param = "/gallery/yourfile.yourext" $fileName = basename($filePath); // will return file name with extension
// alternate
$filePathArr = pathinfo("{$path}{$name}"); // param = "/gallery/yourfile.yourext"
$fileDir = $filePathArr['dirname']; // "/gallery" $fileNameExt = $filePathArr['basename']; // "yourfile.yourext" - same as basename() $fileName = $filePathArr['filename']; // "yourfile" $fileExt = $filePathArr['extension']; // "yourext"
$filePath = "{$filePathArr['dirname']}/{$filePathArr['basename']}; // "/gallery/yourfile.yourext"
I see. So how do I use sha1_file instead of basename? I like how the new filename after sha1_file is so long. The filename of the files as they get to the tmp folder seems boring honestly.
I don't really know what you need. Do you want this?
$finalPath = "/path/to/destination/"; $tmpPath = "/tmp/"; $fileName = "somefile.txt";
$baseFilePath = "{$tmpPath}{$fileName}"; // "/tmp/somefile.txt" $fileNameHash = sha1_file($baseFilePath); // "asdasduosf9d0sa8uf0a9sga" gibberish $hashedFilePath = "{$finalPath}{$fileNameHash}" ; // "/path/to/destination/asdasduosf9d0sa8uf0a9sga"
// copying contents of tmp file to hashed file (text), the convoluted way
$contents = file_get_contents($baseFilePath); $newFile = file_put_contents($hashedFilePath, $contents);
// creating hashed filename from regular and moving it to the proper folder, the right way
rename($baseFilePath, $hashedFilePath); // this moves the file and overwrites if exists, nice and clean, doesn't leave old and unnecessary stuff lying around
|
On January 08 2015 21:55 Manit0u wrote:Show nested quote +On January 08 2015 16:45 SilverSkyLark wrote:On January 08 2015 14:43 Manit0u wrote:That's because basename takes full path to file as its first argument, not just the name and it returns just the filename, not its path. $name = $_FILES['fileToUpload']['tmp_name']; $path = '/gallery/';
$filePath = "{$path}{$name}"; // param = "/gallery/yourfile.yourext" $fileName = basename($filePath); // will return file name with extension
// alternate
$filePathArr = pathinfo("{$path}{$name}"); // param = "/gallery/yourfile.yourext"
$fileDir = $filePathArr['dirname']; // "/gallery" $fileNameExt = $filePathArr['basename']; // "yourfile.yourext" - same as basename() $fileName = $filePathArr['filename']; // "yourfile" $fileExt = $filePathArr['extension']; // "yourext"
$filePath = "{$filePathArr['dirname']}/{$filePathArr['basename']}; // "/gallery/yourfile.yourext"
I see. So how do I use sha1_file instead of basename? I like how the new filename after sha1_file is so long. The filename of the files as they get to the tmp folder seems boring honestly. I don't really know what you need. Do you want this? $path = "/path/to/destination/"; $tmpPath = "/tmp/"; $file = "somefile.txt";
$baseFile = "{$tmpPath}{$file}"; // "/tmp/somefile.txt" $fileHash = sha1_file($baseFile); // "asdasduosf9d0sa8uf0a9sga" gibberish $hashedFile = "{$path}{$fileHash}" ; // "/path/to/destination/asdasduosf9d0sa8uf0a9sga"
// copying contents of tmp file to hashed file (text)
$contents = file_get_contents($baseFile); $newFile = file_put_contents($hashedFile, $contents);
Oh yeah something like this, I'll test it later. Thanks!
btw, are there repercussions in using the gibberish sha1_file uses as the final filename as you save it in your directory?
|
I've updated the reply to let everyone know that this method isn't that great and included the right one (which also works for all types of files).
The only repercussions are that you need to know the new gibberish filename if you want to use it anywhere. I presume you will write the new filename to the database somewhere.
|
Web development at its finest:
|
On January 09 2015 01:57 Manit0u wrote: Web development at its finest: Makes sure only dedicated people will apply.
|
On January 09 2015 02:35 spinesheath wrote:Makes sure only dedicated people will apply.
Makes sure that anyone who knows anything about web dev won't apply...
|
On January 08 2015 10:12 LaNague wrote:I thinkgood programming is something similar to good painting. You have to have a brain for it and you have to practice technique. No matter how much i practiced for my stupid art aclasses in school, in 12 years i did not produce a single good looking picture. And similar, some people in my university are incapable of producing good code, their brain isnt made for it. But university CS degrees arent about programming, you learn mostly other stuff and have some basic programming classes. Same as an art degree is probably not painting things all week (i think?). Show nested quote + hey what would you recommend to programm a little 3d video game? i heared c++ is the best for this?
what libaries would i need besides opengl? i would need something to load files with sound, images, 3d models etc. Which SDK can offer all that. I am looking for something that makes life easy. But i want to go the professional way
that totally depends. If you just want to get it over with and design your game and dont care that you cant really tune everything, then Unity or a similar engine. It can also be used in C# for example. If you are in it for the experience or need something custom, then you need C++ with either directX or openGL. Also, there are shades between those 2 options, but im not a game programmer so i dont know whats hot right now regarding that.
Come on, this is bullshit. You should probably define what you mean by good code, but if you mean readable, then all it takes is to read the book 'Clean Code' by Robert Martin. I don't think one has to have an excellent brain, it is just a discipline.
|
Good code is when you see it and you instantly know how to use it. End of story.
|
On January 09 2015 16:46 Manit0u wrote: Good code is when you see it and you instantly know how to use it. End of story. Manit0u the great lord has spoken words of wisdom.
|
Interpreting quantum physics in a game Posted on October 21, 2013 by spach ‘Learning games’ or ‘games for learning?’ People in our industry tend to use the terms interchangeably, but I prefer ‘games for learning.’ It puts the emphasis on the ‘games’ part. It reminds me that, first and foremost, a game that hopes to foster learning must still be fun. There’s no reason learning itself can’t be fun, of course, whether it happens in a game or not: in fact, I’d say it inherently is. But a game for learning really has to be.
Collaborating with our friends at Google, MincraftEdu and IQIM to make qCraft was a fascinating exercise in finding the intersection of fun Minecraft gameplay and meaningful learning about quantum mechanics. As Dr. M describes in his blog post, our original design was focused more on finding ways to simulate how quantum computers work with things like CNOT gates and qubits. Simulations can be great learning tools, but they aren’t games, and while that design was interesting, it was hard to do the science justice (it turns out simulating a quantum computer with a classical computer is really hard) and the result was not quite as fun as we would have liked. It also didn’t take advantage of the things that can make games great learning tools. In particular, games let you dive in and experience worlds and identities that you never could in real life.
It’s probably unrealistic to think that a Minecraft mod — or any game — could comprehensively cover a topic as complex and hotly debated as quantum mechanics. What we hope a game can do is create a gateway into understanding and experiencing quantum phenomena.
For most people, the notion that something might have different properties based on whether or how it is being observed is a really strange notion totally unlike anything we experience firsthand in the real, macroscopic world. The same is true of other precursor or foundational concepts in quantum mechanics like superposition and entanglement. If a game could help players make this ‘quantum leap’ — and do it in a fun way — that might just be interesting and even useful.
As our design evolved, we asked ourselves what it would mean if players could actually experience, for example, observer dependency in the the Minecraft world. The possibilities for fun gameplay quickly became apparent: structures that reconfigured themselves when you look at them, mazes that change while your back is turned, etc. But could these kind of playful experiences actually change players’ intuitions about how the world works? If they could, would it make real quantum phenomena seem a little less alien? Would players who never studied quantum physics before be motivated to learn more about them? We don’t know the answers to these questions yet, but we’re excited to find out.
Brian Alspach is Executive Vice President at E-Line Media, one of the organizations collaborating on qCraft.
http://qcraft.org/interpreting-quantum-physics-in-a-game/ http://www.thetakeaway.org/story/when-quantum-physics-meets-video-game/ http://www.scienceclarified.com/Qu-Ro/Quantum-Mechanics.html
|
On January 09 2015 16:46 Manit0u wrote: Good code is when you see it and you instantly know how to use it. End of story.
I disagree. Granted there is some truth in what you say. Knowing how to instantly use a method depends more on good practices like variable naming and good commenting but its not nearly enough to qualify a piece of code as good code. Good code is code that has an elegance to it. I can't really put into words but a good comparison is like watching a brilliant piece of artwork that's so cleverly rendered, it just leaves you in awe of how clever the artist is.
Truth is almost no code is like that since programming is something that always seem to have deadlines. There's really never any time to try and be clever. Usually you have to get shit working asap. Many times you're gonna end up with a mess that looks like it could fall apart anytime. MS Windows is a good example of this. I read some years ago where some insider said that the Windows base code is such a huge mess due to all the hacking necessary to make it backward compatible and their deadlines for Windows releases doesn't help either.
But once in a while you get to see code that so beautiful and elegant, you almost wanna cry.
|
On January 10 2015 05:01 VBNiya wrote: Good code is code that has an elegance to it. I can't really put into words but a good comparison is like watching a brilliant piece of artwork that's so cleverly rendered, it just leaves you in awe of how clever the artist is. Absolutely not. Good code is code that is so simple that you never recognize it as something special.
|
but what if you can make it work faster with a more convoluted method? good code is also a function of the requirements and weighted criteria.
|
On January 10 2015 05:25 ComaDose wrote: but what if you can make it work faster with a more convoluted method? good code is also a function of the requirements and weighted criteria. Then there's a good chance I'll scold you for thinking about optimization before profiling. Also then there likely is a way to make it faster without convoluting the code.
|
|
|
|