pinacoladaxb Posted May 17, 2008 Share Posted May 17, 2008 I'm sure I could find this information by doing a google search, but I honestly don't know what to search for. I'm trying to make a script that interacts with an application I'm making. What I need is an upload script. The application finds the file and connects to the script. For example: www.flufferfluff.com/games/battles/upload.php?file=C:\Documents and Settings\Laima\My Documents\image.bmp. Every time I search for the answer, I get an example with a form in it. Like this: <!-- The data encoding type, enctype, MUST be specified as below --> <form enctype="multipart/form-data" action="__URL__" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form> How would I modify that? Thanks. Quote Link to comment Share on other sites More sharing options...
pinacoladaxb Posted May 17, 2008 Author Share Posted May 17, 2008 Actually, here's an even better script I found (only requires one php file): <form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="2048000"> File: <input name="userfile" type="file" /><br /> <input type="submit" value="Upload" /> </form> <?php if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) { copy($_FILES["userfile"]["tmp_name"], "images/" . $_FILES["userfile"]["name"]); echo "<p>File uploaded successfully.</p>"; } ?> ...but it still uses a form. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 17, 2008 Share Posted May 17, 2008 You can't pass a local file path as a GET variable and expect to be able to use it on the receiving page. You NEED to use an upload script like the ones you found. Please elaborate on your problem so we can help you better. Quote Link to comment Share on other sites More sharing options...
pinacoladaxb Posted May 17, 2008 Author Share Posted May 17, 2008 Well, I guess I may as well give you the full story. I'm making a game that includes a level editor. Since all of the files are going to be stored online, I need an upload script. For each level made, 2 files are uploaded: an array and a screenshot. I plan to upload the array in /games/battles/levels and the screenshot in /games/battles/images. I really don't know how to further explain this situation. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 17, 2008 Share Posted May 17, 2008 What do you mean by "an array is uploaded"? And for the image uploading, you need to basically use the form that you have already found (notice the encytype attribute on the form tag!), and you need to do stronger file upload checks and store the path to the image in the database. Quote Link to comment Share on other sites More sharing options...
pinacoladaxb Posted May 17, 2008 Author Share Posted May 17, 2008 Aah! Slow down. I'm not that smart. I'm new to all of this. By an "array," I mean a file with data stored in it. It can be opened with notepad, but under its properties, it says: Type of file: File. You say I can use the same code I found? How do I change it? What do you mean by "you need to do stronger file upload checks and store the path to the image in the database." I am really lost here. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 17, 2008 Share Posted May 17, 2008 Do you have ANY code as of yet? Like, a database connection script, etc? Quote Link to comment Share on other sites More sharing options...
pinacoladaxb Posted May 17, 2008 Author Share Posted May 17, 2008 I have a database connection script, but for something entirely different. What exactly are you telling me to do? EDIT: Key word: Exactly. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 17, 2008 Share Posted May 17, 2008 Let me sort of plot this out for you so you can see what I mean, then we can get to code after you understand this: 1) You present a form to the user. It has 2 upload spots: 1 file, and 1 image. 2) The user selects the files and submits. 3) On the PHP side, you take these files, make sure they're of the appropriate type and size, and move them to their final directory, because uploaded files are put in a "temporary" directory until you move them. 4) Take the path name to the file and the image and store them in the database in the same row, so they're associated. Then, they can have an ID that corresponds to certain level, if you want. Quote Link to comment Share on other sites More sharing options...
pinacoladaxb Posted May 17, 2008 Author Share Posted May 17, 2008 I actually understand all of that, but step 4 isn't needed. I already have that sorted out in my app. The thing is, the user shouldn't ever see the upload page. In fact, the user may not even know that the level is being uploaded. It should be hidden. EDIT: The way the game finds the level image is by getting $Player_Name . "&" . $Level_Name . ".bmp". Getting the array is almost the same thing, just without the ".bmp." Of course, it isn't php I am using, but you get how it works. The "&" is used as a delimiter. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 17, 2008 Share Posted May 17, 2008 So you need to take the level ID and the Player Name and use it in the move_uploaded_file() call. Quote Link to comment Share on other sites More sharing options...
pinacoladaxb Posted May 17, 2008 Author Share Posted May 17, 2008 You JUST lost me again. EDIT: I'm not trying to frustrate you, but I really had no idea what you just said. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 17, 2008 Share Posted May 17, 2008 Can I see what you have so far? Like, show me how you plan to implement the level configuration file that you upload. Quote Link to comment Share on other sites More sharing options...
pinacoladaxb Posted May 17, 2008 Author Share Posted May 17, 2008 Well, with the software I use, it's not pure scripting. You are able to use pre-made C++ scripts that can be submitted by anyone, so there are hundreds of them. One that I am using is an array script. It is able to create a file that stores the data and interprets the file so that I can easily make a loop to add the game elements to the X and Y coordinates of the game map corresponding to the array file. If you want to see how it looks, I made a demo that I sent to a few friends: http://www.pauliukonis.com/miscfiles/The%20Battles%20of%20Fluffer%20Fluff%20Meadows%20-%20Level%20Editor.exe Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 17, 2008 Share Posted May 17, 2008 Oh, it makes a .exe of it? I don't run windows, so I'm not even going to bother downloading it. So you just want people to upload files and screenshots? O_O Quote Link to comment Share on other sites More sharing options...
pinacoladaxb Posted May 17, 2008 Author Share Posted May 17, 2008 YES. lol. I didn't think I was asking for much. I'll give you some screenshots in a second. By the way, I can make a Java file out of it, but my game uses specific windows directories and uses some scripts that can't be run on macs. Sorry. Quote Link to comment Share on other sites More sharing options...
pinacoladaxb Posted May 17, 2008 Author Share Posted May 17, 2008 Screenshots: Level selection screen: Submitting a level (for inclusion in the final game. This has nothing to do with what we're talking about.) Making a level: So there you go. That's not what the game looks like. Just the demo. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 17, 2008 Share Posted May 17, 2008 I don't use a Mac either. But wait. Is this a web app? O_O It needs to be a web app for PHP to do anything (unless you run it the CLI, which can get a tad complicated). Quote Link to comment Share on other sites More sharing options...
pinacoladaxb Posted May 17, 2008 Author Share Posted May 17, 2008 Yes. The one I'm making is a web app. The demo is not. Quote Link to comment Share on other sites More sharing options...
phorman Posted May 17, 2008 Share Posted May 17, 2008 YES. lol. I didn't think I was asking for much. I'll give you some screenshots in a second. By the way, I can make a Java file out of it, but my game uses specific windows directories and uses some scripts that can't be run on macs. Sorry. Ok, I see what you are attempting to do, and if your game allows a place to call php code, you can use php to call FTP functions to send files to the server in the background, without a form having to be submitted. Contrary to the message title, this is not a basic question. To point you in the right direction, checkout www.php.net and specifically search for FTP to see what I mean. Quote Link to comment Share on other sites More sharing options...
pinacoladaxb Posted May 17, 2008 Author Share Posted May 17, 2008 Well, when I started this thread, I thought all I'd have to do is change the form page a little. I had no idea that directories could not be sent using the GET function. I'll take a look at the ftp thing. Quote Link to comment Share on other sites More sharing options...
pinacoladaxb Posted May 19, 2008 Author Share Posted May 19, 2008 I've tried many things, but none seem to work to upload something to my server. Am I doing this right? Here's something I tried: <? $name = "hi.txt"; $filename = "C:\Documents and Settings\Laima\My Documents\hi.txt"; //-- Code to Transfer File on Server Dt: 06-03-2008 by Aditya Bhatt --// //-- Connection Settings $ftp_server = "pauliukonis.com"; // Address of FTP server. $ftp_user_name = "pauliuko"; // Username $ftp_user_pass = "32443rewfdf"; // Password $destination_file = ""; //where you want to throw the file on the webserver (relative to your login dir) $conn_id = ftp_connect($ftp_server) or die("<span style='color:#FF0000'><h2>Couldn't connect to $ftp_server</h2></span>"); // set up basic connection $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("<span style='color:#FF0000'><h2>You do not have access to this ftp server!</h2></span>"); // login with username and password, or give invalid user message if ((!$conn_id) || (!$login_result)) { // check connection // wont ever hit this, b/c of the die call on ftp_login echo "<span style='color:#FF0000'><h2>FTP connection has failed! <br />"; echo "Attempted to connect to $ftp_server for user $ftp_user_name</h2></span>"; exit; } else { //echo "Connected to $ftp_server, for user $ftp_user_name <br />"; } $upload = ftp_put($conn_id, $destination_file.$name, $filename, FTP_BINARY);// upload the file if (!$upload) {// check upload status echo "<span style='color:#FF0000'><h2>FTP upload of $filename has failed!</h2></span> <br />"; } else { echo "<span style='color:#339900'><h2>Uploading $name Completed Successfully!</h2></span><br /><br />"; } ftp_close($conn_id); // close the FTP stream ?> EDIT: I forgot to censor my password. Glad I caught that!! EDIT 2: Here's the page I got the code from: http://us2.php.net/manual/en/function.ftp-put.php Quote Link to comment Share on other sites More sharing options...
pinacoladaxb Posted May 19, 2008 Author Share Posted May 19, 2008 I feel so forgotten. :'( Please. I need help soon. I have a deadline approaching fast. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 19, 2008 Share Posted May 19, 2008 Sorry, I went to sleep before I get to reply to you before. Now let me get this straight. You have a web server and you want a form that lets users upload something directly to your server, right? Quote Link to comment Share on other sites More sharing options...
pinacoladaxb Posted May 19, 2008 Author Share Posted May 19, 2008 Don't apologize. You're the one helping me. There is no forum. Just an upload. Like I said, it is possible that the user will never know their levels are stored online if they aren't very bright. On the game side, the user makes a level. When they save it, the game brings the array file and screenshot to http://flufferfluff.com/games/battles/upload.php. Then, the script uploads the files from the user's computer. The way the script knows where the files are located is they are always located in the SAME spot. For example, they could be always located in C:\Program Files\Game_Title\levels. I just have no idea how to do that. The script I found should do the trick, but I think I did something wrong. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.