473,725 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Upload Script

41 New Member
Hi, I'm creating a upload form for an open-source games track and kart repos. Basically I'm trying to code a upload form that allows user to select, from a pop-up menu, if they are uploading a kart or a track; then they select the file (File MUST be gziped or bziped). If they choose that the file is a kart, the file will be uploaded in ./karts,; if a track, it will be uploaded in ./tracks.
So I did some searching on the internet, and coded a basic outline for part of my upload form.

<
Expand|Select|Wrap|Line Numbers
  1. ?php
  2. $target = "upload/";
  3. $target = $target . basename( $_FILES['uploaded']['name']) ;
  4. $ok=1;
  5.  
  6. //NOT CURRENTLY USED
  7. //This is our size condition
  8. //if ($uploaded_size > 350000)
  9. //{
  10. //echo "Your file is too large.<br>";
  11. //$ok=0;
  12. //}
  13.  
  14. //This is our limit file type condition
  15. if (!($uploaded_type =="application/gzip" || $uploaded_type =="application/x-gzip"|| $uploaded_type =="application/x-bz2" || $uploaded_type =="application/x-bzip" || $uploaded_type =="application/bzip"))
  16. {
  17. echo "File MUST be gziped or bziped<br>";
  18. $ok=0;
  19. }
  20.  
  21. //Here we check that $ok was not set to 0 by an error
  22. if ($ok==0)
  23. {
  24. Echo "Sorry your file was not uploaded";
  25. }
  26.  
  27. //If everything is ok we try to upload it
  28. else
  29. {
  30. if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
  31. {
  32. echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded,<br>it will be in the add--on manager shortly";
  33. }
  34. else
  35. {
  36. echo "Sorry, there was a problem uploading your file.";
  37. }
  38. }
  39. ?> 
Expand|Select|Wrap|Line Numbers
  1. <form enctype="multipart/form-data" action="upload.php" method="POST">
  2. Please choose a file: <input name="uploaded" type="file" /><br />
  3. <input type="submit" value="Upload" />
  4. </form> 
PS: The finished work will most likely be CC-BY
Nov 21 '08 #1
9 1624
nathj
938 Recognized Expert Contributor
jpenguin,

Well, that's lovely. Is there a problem with this script, a question you need help on or are you just showing us that you can copy scripts you found on-line?

If there is some trouble with it I'd be happy to help but right now I'd be guessing.

If you need help please provide the following:

1. Any error messages you are getting including the code that the message references
2. What the code should do
3. What the code does not do that it should do
4. What the code does do that is should not do

That information will lead to a more helpful less sarcastic answer then mine.

Cheers
nathj
Nov 21 '08 #2
Markus
6,050 Recognized Expert Expert
What does "PS: The finished work will most likely be CC-BY" mean?
Nov 21 '08 #3
jpenguin
41 New Member
1. I'm sorry I wasn't very clear; I', trying to learn basic PHP and thought this would be a good project to learn on. I've been doing some reading online, but don't get how I can create a drop-down menu suited for my use, because I've found so many complete different examples online.
1.1 Right now I have the file type checking, what I need in it is a place where the user can select "kart or track"

2. CC-BY is a license, I want the final script to be under. CC is like GPL but more liberal, BY is what the choose to stand for attribution; so, I'm only mentioning it so you know that you will get credit if I use any help you give.

We don't even have a web-server picked out, I think it is going to be a Unix based server.

Once I get the menu figured out I will add more to it- like a screen-shot uploader, and a name field, maybe even mysql integration; but that's all for later.
Nov 21 '08 #4
Markus
6,050 Recognized Expert Expert
1. I'm sorry I wasn't very clear; I', trying to learn basic PHP and thought this would be a good project to learn on. I've been doing some reading online, but don't get how I can create a drop-down menu suited for my use, because I've found so many complete different examples online.
1.1 Right now I have the file type checking, what I need in it is a place where the user can select "kart or track"
So you need to add a drop down menu?

Do you have the drop-down menu already created in your HTML form?
If not, here's how your drop down should look:
Expand|Select|Wrap|Line Numbers
  1. <select name="uploadtype">
  2.   <option value="kart">Kart</option>
  3.   <option value="track">Track</option>
  4. </select>
  5.  
That should be in your html form.

Then you will receive the value of the drop down form by doing this server-side:

Expand|Select|Wrap|Line Numbers
  1. $type = $_POST['uploadtype'];
  2.  
2. CC-BY is a license, I want the final script to be under. CC is like GPL but more liberal, BY is what the choose to stand for attribution; so, I'm only mentioning it so you know that you will get credit if I use any help you give.
Oh that's cool, our names on your product. Aha. You don't have to do that.

We don't even have a web-server picked out, I think it is going to be a Unix based server.
Sounding good.

Once I get the menu figured out I will add more to it- like a screen-shot uploader, and a name field, maybe even mysql integration; but that's all for later.
Database is the way forward, my friend, and we'll be here to help.

Markus.
Nov 21 '08 #5
jpenguin
41 New Member
Thanks for all your help., I think I've got something that will work. Of coarse I have no way of testing it yet, so for all I know it could crash and burn.
I'll have to wait for replies from the project developers to see where we should store info like names (after all they have to be able to write C++ code that can retrieve it).

So now I want to know what the best way to display info specific to karts or tracks; If they select "kart"- I want to display one additional upload field, if they select "track"- two additional upload field should be displayed.

Here is my current HTML code
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4.   <meta
  5.  content="text/html; charset=ISO-8859-1"
  6.  http-equiv="content-type">
  7.   <title>upload form</title>
  8. </head>
  9. <body>
  10. <form enctype="multipart/form-data"
  11.  action="upload.php" method="post">What
  12. type of
  13. add-on are you uploading:&nbsp;
  14.   <select name="uploadtype">
  15.   <option value="addons/karts/">Kart</option>
  16.   <option value="addons/tracks/">Track</option>
  17.   </select>
  18.   <br>
  19. Is the add-on's license compatible with Debain: <input
  20.  name="license" value="Yes" type="radio">Yes
  21.   <input name="your question2"
  22.  value="No" type="radio">No<br>
  23. Who is the
  24. author: <input name="author:"
  25.  size="50" maxlength="100" type="text"><br>
  26.   <br>
  27. What is the name of the track/kart:<input
  28.  name="name:" size="50" maxlength="100" type="text"><br>
  29.   <br>
  30. Please
  31. choose a file: <input name="uploaded"
  32.  type="file"><br>
  33.   <input value="Upload" type="submit"></form>
  34. <br>
  35. </body>
  36. </html>
  37.  
My PHP code
Expand|Select|Wrap|Line Numbers
  1. /*This file is under a CC-BY license, it has beeen coded by jpenguin with help from
  2. som freindly people at the bytes.com forum*/
  3. <?php
  4. $allow = $_POST['license'];
  5. $type = $_POST['uploadtype'];
  6. $target = $type . basename( $_FILES['uploaded']['name']) ;
  7. $ok=1;
  8.  
  9. //NOT CURRENTLY USED
  10. //This is our size condition
  11. //if ($uploaded_size > 350000)
  12. //{
  13. //echo "Your file is too large.<br>";
  14. //$ok=0;
  15. //}
  16.  
  17. //This is our limit file type condition
  18. if (!($uploaded_type =="application/gzip" || $uploaded_type =="application/x-gzip"|| $uploaded_type =="application/x-bz2" || $uploaded_type =="application/x-bzip" || $uploaded_type =="application/bzip"))
  19. {
  20. echo "File MUST be gziped or bziped<br>";
  21. $ok=0;
  22. }
  23. //license check
  24. if ($allow =="no")
  25. {
  26. echo "All add-ons MUST have a Debain campatable license"
  27. $ok=0;
  28. }
  29. //Here we check that $ok was not set to 0 by an error
  30. if ($ok==0)
  31. {
  32. Echo "Sorry your file was not uploaded";
  33. }
  34.  
  35. //If everything is ok we try to upload it
  36. else
  37. {
  38. if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
  39. {
  40. echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded,<br>it will be in the add--on manager shortly";
  41. }
  42. else
  43. {
  44. echo "Sorry, there was a problem uploading your file.";
  45. }
  46. }
  47. ?> 
PS–I am using NVU to create my HTML form. a screenshot of the 'preview' is here
Nov 21 '08 #6
Markus
6,050 Recognized Expert Expert
Have you not tested your code?!

If you're only looking for a test server, why not setup a localhost. Every developer in their right minds has one.

What's a localhost, you ask? A localhost, is a webserver that is on your local machine.

Googe for xampp or easyphp for very easily installed localhosts.

--

The 'select one -> one upload field, select 2 -> two upload fields' thing, can be accomplished with Javascript. Head over to that forum and ask your question there.
Nov 22 '08 #7
jpenguin
41 New Member
Your write, I already have APACHE, I just need to get PHP; then I'll test the code.
Nov 22 '08 #8
jpenguin
41 New Member
So I'm just about done. I am trying to save some info ther enters in a txt file, I actually have a function for that, but I can't get the name the way I want it nor save it in the right spot; if the user uploads "mytrack.tb z", the text file should be named "mytrack.tx t" and it should go in the same directory as the uploaded .tbz

My HTML code-
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4.   <meta content="text/html; charset=ISO-8859-1"
  5.  http-equiv="content-type">
  6.   <title>upload form</title>
  7. </head>
  8. <body>
  9. <form enctype="multipart/form-data" action="upload.php" method="post">What
  10. type of
  11. add-on are you uploading:&nbsp;
  12.   <select name="uploadtype">
  13.   <option value="karts/">Kart</option>
  14.   <option value="tracks/">Track</option>
  15.   </select>
  16.   <br>
  17. Is the add-on's license compatible with Debain: 
  18.   <select name="license">
  19.   <option value="no">no</option>
  20.   <option value="yes">yes</option>
  21.   </select>
  22.   <br>
  23.   <br>
  24.  Who is the
  25.  author: <input name="author" type="text"><br>
  26.    <br>
  27.  What is the name of the track/kart:<input name="title" type="text"><br>
  28.    <br>  <br>
  29.   <br>
  30. Please
  31. choose the archive for the kart/track: <input name="uploaded"
  32.  type="file"><br>
  33.   <input value="Upload" type="submit">
  34.   <br>
  35. </form>
  36. </body>
  37. </html>
  38.  
Parts of my PHP code-
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $author=$_POST['author'];
  3. $title=$_POST['title']; 
  4. $allow = $_POST['license'];
  5. $type = $_POST['uploadtype'];
  6. $target = $type . basename( $_FILES['uploaded']['name']) ;
  7. $ok=1;
  8.  
  9. //find the file extention
  10. function findexts ($filename)
  11. {
  12. $filename = strtolower($filename) ;
  13. $exts = split("[/\\.]", $filename) ;
  14. $n = count($exts)-1;
  15. $exts = $exts[$n];
  16. return $exts;
  17. }
  18. $ext = findexts ($_FILES['uploaded']['name']) ;
  19.  
Expand|Select|Wrap|Line Numbers
  1.     if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
  2.     {
  3.         echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded,<br>it will be in the add--on manager shortly";
  4.         //The collects the athor and the addon name
  5.         //and stores them in a text file
  6.         $File = (($target)".txt");            //This line is causing the problem
  7.         $Handle = fopen($File, 'w');
  8.         fwrite($Handle, $author);
  9.         fwrite($Handle, "\n");
  10.         fwrite($Handle, $title);
  11.         fclose($Handle); 
  12.             if ($type =="karts/")
  13.             {
  14.                 //The next line is server specific
  15.                 header( 'Location: http://josh-dyes-computer.local/~jpenguin/stk/Kart upload.html' ) ;
  16.             }
  17.             if ($type =="tracks/")
  18.             {
  19.                 //The next line is server specific
  20.                 header( 'Location: http://josh-dyes-computer.local/~jpenguin/stk/Track upload.html' ) ;
  21.             }
  22.     }
  23.     else
  24.     {
  25.         echo "Sorry, there was a problem uploading your file.";
  26.     }
  27. }
  28. ?>
Nov 23 '08 #9
jpenguin
41 New Member
nevermind, I got it!

Thanks for all your help
Nov 24 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2934
by: Tihon | last post by:
Hello! I again need your help, just can't understand whats going on. Got this upload pictures form and it's having problem handling large files (~1.5 - 2 MB). Everything works fine if i just upload files, like this: copy ($myfile, $uploadfolder . "/" . $myfile_name); Everything works fine, it can process large files and everything, but i need to make sure that people only upload pictures, so i change
1
3022
by: PeterB | last post by:
Hi! I'm using Pure ASP File Upload (http://www.asp101.com/articles/jacob/scriptupload.asp) to upload a file from a client to a server. I am testing both on a local IIS and a remote server. The welcome page has a browse button (for locating your local file), a textfield where the path is displayed, and a upload button. When clicking upload a VB ASP script is run, and the outcome is displayed on a new page. 1. On my local machine I got the...
9
3832
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web site for a small club I belong to and one of the features I would like to include is the ability to allow users to upload image files. unfortunately the servers web root www folder only allows READ and EXECUTE permissions, which makes it...
7
3189
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file" name="file_1" size=46 /><input type=submit /> so, after adding a few files, the input fields look like this:
9
20897
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at rapidshare news : http://images.rapidshare.com/software/rsapi.pl If you test it you will see that you can upload one file at time. I try to modify it in that way that script can read a text file with the names of the files i want to...
9
3895
by: Steve Poe | last post by:
I work for an animal hospital trying to use PHP to store an animal's dental x-rays to a file server. I can browse for the xray on the local desktop computer then click "Upload Image". This works fine. The doctors want fewer steps to follow. So, it was asked if I can configure the browser to load/submit the image 'xray.tif' each time they click "Upload Image" instead of the doctor/animal technician having to look for for dental x-ray...
21
34427
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most obvious of which is the sharing of files. For example, you upload images to a server to share them with other people over the Internet. Perl comes ready equipped for uploading files via the CGI.pm module, which has long been a core module and allows users...
1
3953
by: kksandeep | last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help the script i found is some helpful but not too that i need my objective is this that when i uplod a file it should be desply on same page with ajax uplod after when i refresh page this should be not remains longer and on clicking other image its replase previous image plz help how i can do this the...
5
3289
by: camphor | last post by:
hi, I have found an upload script in hotscripts and have implemented it into the website, I followed the installation steps to 'give write permissions to php on the upload folder (which is _uploadedfiles_xxxx) (php must be allowed to move uploaded files to this folder' - uploadedfiles_xxxx. I typed <?php chmod ('_uploadedfiles_xxxx',640); ?> into notepad and saved it as php in the uploaded_xxxx folder, when I went to test it, the error...
24
7716
by: owz2008 | last post by:
This has probably been covered before but could not find a similar thread. Basically I have created a form which can be viewed at www.icomworks.co.uk/canvaspayform.html I want to submit the form along with the file so that they are both placed on my server... I have created a folder on my server in my public_html called myscripts and have saved my upload.cgi script into that folder. my form points to that script but when I fill in the...
0
9398
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6699
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6006
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4507
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4776
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3216
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2626
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2153
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.