...

View Full Version : How would I create a form that uploads things to a webpage?



BabyJack
05-20-2008, 05:16 PM
Hi, I was wanting an upload form similar to thesimsresource.com. Where you upload a .sims2pack file, an image and a description and then, once uploaded, goes into a page. Without me or an other administrator putting them on.

How would I do this - and I am not willing to pay any money for this.


BabyJack :)

derzok
05-20-2008, 05:34 PM
http://www.tizag.com/phpT/fileupload.php shows you how to make an upload form in php/html. You'll need to make a few other forms for any other info that you want to be displayed with the webpage. The submit action for the form should send the $_POST info to a script that will store the information in either a flat file or a database. I'd recommend using a database.

Here's a script I wrote for one of my clients once:


<div id="center">
<?
include_once("inc.php");
if($session != 1) {
print $login_error;
return;
}
db_connect();
if(isset($_GET['submit'])) {
$target_path = "photos/";
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
$time = time();
$path = "photos/";
$filename = $time.".jpg";
$medium_thumb = $time."_med.jpg";
$small_thumb = $time."_small.jpg";
if(rename($target_path,$path.$filename)) {
exec("convert ".$path.$filename ." -resize 90x68 ".$path.$small_thumb);
exec("convert ".$path.$filename ." -resize 160x120 ".$path.$medium_thumb);
} else {
print "Some sort of error occured! Feeling helpful? Contact your webadmin.</div><div id=\"footerline\"></div>";
}
$description = (empty($_POST['desc'])) ? "" : mysql_real_escape_string($_POST['desc']);
$query = "INSERT INTO `photos` (`desc`,`filename`,`med_thumb`,`small_thumb`)
VALUES ('$description','$filename','$medium_thumb','$small_thumb')";
mysql_query($query);
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
db_disconnect();
return;
} else{
?>
<form enctype="multipart/form-data" action="index.php?page=upload_photos&submit=true" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
Photo to upload: <input name="uploadedfile" type="file" /><br /><br/>
Photo description <i>(This will appear under the photo in the gallery)</i>:<br/> <input type="text" name="desc" size="50"><br/><br/>
<div align="center"><input type="submit" value="Upload!" /></div>
</form>
<?
}
?>


As you can see, my action= for the form submits to the same document that holds the form - this is a self containing document! The only things you need to change are the action= so that it does not require index.php, the database table names, and you'd have to implement dbconnect() and db_disconnect().

BabyJack
05-20-2008, 05:41 PM
I am new to PHP, but what do I put to show the uploads in another webpage?
And how do I upload another file type (.sims2Pack)?

mlseim
05-20-2008, 06:15 PM
There are other issues here that will change how it can (or should) be done.

1) How many file uploads do you expect?
2) How large are the files (less than 1MB, 10MB, 100MB?)
3) Can anyone upload, or is there a need for security,
like a member registration system?
4) Can anyone administer the files, or a control panel
that only an "admin" person can access?
5) Can anyone view the list of files, or members only?
6) Do the files (or data) need to be protected in a special directory?
(again ... describe security needs).

BabyJack
05-20-2008, 06:26 PM
1. About 30 per week
2. files will be more than 100MB
3. member Registration form
4. Only an admin person can access the CP
5. Anyone
6. No, however, they have to have a backup in an external file.

aedrin
05-20-2008, 08:57 PM
2. files will be more than 100MB


This alone will mean you are going to have to find a more advanced solution. And it doesn't appear you are at an advanced level of website creation.

derzok
05-20-2008, 09:04 PM
You could give members (or anyone who you want) upload access to an FTP site. You could easily script the server to reject anything that doesn't end in a .sims2Pack file extension as well.

Of course, there are other security issues that you have to consider when you set up an open ftp server...

BabyJack
05-20-2008, 10:14 PM
. And it doesn't appear you are at an advanced level of website creation.
*coughs* www.wifee.missingstudios.com

FWDrew
05-20-2008, 10:44 PM
. And it doesn't appear you are at an advanced level of website creation.
*coughs* www.wifee.missingstudios.com


SQL ERROR [ mysql4 ]

Table 'missings_wifee.phpbb3_config' doesn't exist [1146]

and another error....
http://www.wifee.missingstudios.com/media/index.php
^^ From your site, figured you might want to know. Also about half the links dont work. Normally, I wouldnnt say anything but since you posted a link to your site I can only assume you wanted some kind of feedback.

And you should get that coughed looked at, it doesnt sound good.

Drew

mlseim
05-21-2008, 05:13 AM
So, looking at your specs now, it looks like you should start
with a PHP/MySQL membership script (many free ones available).
That will control your user's access. It will also control the admin panel.

The next step would be the FTP part ... because of the large file size.

Quote from first post: "...and I am not willing to pay any money for this."

I think you can find all the scripts you need, for free (using Google).

BabyJack
05-21-2008, 10:39 AM
So, looking at your specs now, it looks like you should start
with a PHP/MySQL membership script (many free ones available).
That will control your user's access. It will also control the admin panel.

The next step would be the FTP part ... because of the large file size.

Quote from first post: "...and I am not willing to pay any money for this."

I think you can find all the scripts you need, for free (using Google).

Google, google, google. Thanks


*yes i know I am putting messages in code.


FWDrew is an unknown quantity at this point

Quote:
Originally Posted by BabyJack View Post
Code:

. And it doesn't appear you are at an advanced level of website creation.

*coughs* www.wifee.missingstudios.com
Quote:
SQL ERROR [ mysql4 ]

Table 'missings_wifee.phpbb3_config' doesn't exist [1146]
and another error....
http://www.wifee.missingstudios.com/media/index.php
^^ From your site, figured you might want to know. Also about half the links dont work. Normally, I wouldnnt say anything but since you posted a link to your site I can only assume you wanted some kind of feedback.

And you should get that coughed looked at, it doesnt sound good.

My friend and I are working on the forums. I need to delete the 1,000 tables o.o.

And yes, some of the links don't work. It has only been up since Sunday.

aedrin
05-21-2008, 07:50 PM
. And it doesn't appear you are at an advanced level of website creation.
*coughs* www.wifee.missingstudios.com

I was talking about the realm of PHP (this being a PHP forum). If you were at an advanced stage, you wouldn't be asking this question on this forum.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum