/    Sign up×
Community /Pin to ProfileBookmark

Upload images using form

:p hello!! :p

I am wanting a script that is basically a form were users can fill out their name and e-mail but also upload images.
The file types I want are .gif .png .jpeg and .jpg
I have got a code at the moment which allows users to upload their images, and the images go directly to a folder in my site. The problem is…i don’t know how to chage it so they can fill out their name and email too.

<? include’cookiecheck.php’; ?> <? include($headervar.$skin.$extension); ?>
<center>
<font face=”arial” color=”ffffff” size=”1pt”>
<html>
<head><title>Upload</title></head>
<body>

<?php

require(“fileupload-class.php”);

#——————————–#

# Variables

#——————————–#

// The path to the directory where you want the
// uploaded files to be saved. This MUST end with a
// trailing slash unless you use $path = “”; to
// upload to the current directory. Whatever directory
// you choose, please chmod 777 that directory.

$path = “uploads/”;

// The name of the file field in your form.

$upload_file_name = “userfile”;

// ACCEPT mode – if you only want to accept
// a certain type of file.
// possible file types that PHP recognizes includes:
//
// OPTIONS INCLUDE:
// text/plain
// image/gif
// image/jpeg
// image/png

// Accept ONLY gifs’s
#$acceptable_file_types = “image/gifs”;

// Accept GIF and JPEG files
$acceptable_file_types = “image/gif|image/jpeg|image/pjpeg”;

// Accept ALL files
#$acceptable_file_types = “”;

// If no extension is supplied, and the browser or PHP
// can not figure out what type of file it is, you can
// add a default extension – like “.jpg” or “.txt”

$default_extension = “”;

// MODE: if your are attempting to upload
// a file with the same name as another file in the
// $path directory
//
// OPTIONS:
// 1 = overwrite mode
// 2 = create new with incremental extention
// 3 = do nothing if exists, highest protection

$mode = 2;

#——————————–#

# PHP

#——————————–#
if (isset($_REQUEST[‘submitted’])) {
/*
A simpler way of handling the submitted upload form
might look like this:

$my_uploader = new uploader(‘en’); // errors in English

$my_uploader->max_filesize(30000);
$my_uploader->max_image_size(96, 96);
$my_uploader->upload(‘userfile’, ‘image/gif’, ‘.gif’);
$my_uploader->save_file(‘uploads/’, 2);

if ($my_uploader->error) {
print($my_uploader->error . “<br><br>n”);
} else {
print(“Thanks for uploading ” . $my_uploader->file[‘name’] . “<br><br>n”);
}
*/

// Create a new instance of the class
$my_uploader = new uploader($_POST[‘language’]); // for error messages in french, try: uploader(‘fr’);

// OPTIONAL: set the max filesize of uploadable files in bytes
$my_uploader->max_filesize(15000);

// OPTIONAL: if you’re uploading images, you can set the max pixel dimensions
$my_uploader->max_image_size(96, 96); // max_image_size($width, $height)

// UPLOAD the file
if ($my_uploader->upload($upload_file_name, $acceptable_file_types, $default_extension)) {
$my_uploader->save_file($path, $mode);
}

if ($my_uploader->error) {
echo $my_uploader->error . “<br><br>n”;

} else {
// Successful upload!
print($my_uploader->file[‘name’] . ” was successfully uploaded! <a href=”” . $_SERVER[‘PHP_SELF’] . “”>Add another?</a><br>”);

// Print all the array details…
//print_r($my_uploader->file);

// …or print the file
if(stristr($my_uploader->file[‘type’], “image”)) {
echo “<img src=”” . $path . $my_uploader->file[‘name’] . “” border=”0″ alt=””>”;
} else {
$fp = fopen($path . $my_uploader->file[‘name’], “r”);
while(!feof($fp)) {
$line = fgets($fp, 255);
echo $line;
}
if ($fp) { fclose($fp); }
}
}
}

#——————————–#

# HTML FORM

#——————————–#
?>
<form enctype=”multipart/form-data” action=”<?= $_SERVER[‘PHP_SELF’]; ?>” method=”POST”>
<input type=”hidden” name=”submitted” value=”true”>

Upload this file:<br>
<input name=”<?= $upload_file_name; ?>” type=”file”>
<br><br>

Error Messages:<br>
<select name=”language”>
<option value=”en”>English</option>
<option value=”fr”>French</option>
<option value=”de”>German</option>
<option value=”nl”>Dutch</option>
<option value=”it”>Italian</option>
<option value=”fi”>Finnish</option>
<option value=”es”>Spanish</option>
<option value=”no”>Norwegian</option>
<option value=”da”>Danish</option>
</select>
<br><br>

<input type=”submit” value=”Upload File”>
</form>
<hr>

<?php
if (isset($acceptable_file_types) && trim($acceptable_file_types)) {
print(“This form only accepts ” . str_replace(“|”, ” or “, $acceptable_file_types) . ” filesn”);
}
?>

</body>
</html>
</center>
</font>

<? include($footervar.$skin.$extension); ?>

That is what I have so far. I just need to know how to get it so it shows their name and e-mail. E-mail is not that important just as long as i know their name so if their is any way someone culd edit the script so that it just changes the image name to the users name, that would be good too! :p

Love Yasmin x

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@bokehAug 15.2005 — <>
Copy linkTweet thisAlerts:
@Jazzy-YasiauthorAug 15.2005 — I was going to credit them. Like if they make a graphic and i put it on, i need to say who made it. The e-mail is just so I can e-mail them back! but thats not too important!
Copy linkTweet thisAlerts:
@Jazzy-YasiauthorAug 16.2005 — Can anyone help?? ?
Copy linkTweet thisAlerts:
@robertspeerAug 16.2005 — newbie 2 newbie: read the sticky post at the top of the forum, I'm sure it has something about specific questions, properly formatting your code posts so they are color coded and easier to read, and generally how to make it more likely you will get a good answer.

My attempt at an answer:

if nothing is passed that script will print out an HTML form

you need to add 2 <input type=text> fields to your HTML Form

name one name and the other email

if you are unfamilier with html forms check out www.w3schools.com I suspect they have a good forms tutorial.

When a user clicks submit the image, name, & email are passed back to the script of the same name (think juggling)

the script detects that something is being passed to it this time and processes the results.

Currently it only spits out the file into a directory

you want to add

$name = $_REQUEST['name'];

$email = $_
REQUEST['email'];

then:

1) connect to a your database program (probably MySQL)

2) select your database

(a) if you have'nt already create a table with fields id, name, email, filename w/ id being an auto number

3) create your query, something like

$query = "INSERT '', ".$name.", ".$email.", ".$my_uploader->file['name']."

$query .= " INTO TableName"

4) then apply the query string to your db program

$result = mysql_query($query);

5) if $result == TRUE then you've added them to your db

You may also want to append the id of the associated table row to the image name so all the image names will be unique.

Be aware that this is very rough and will probably take some work on your part to refine & and correct an error.

robert
Copy linkTweet thisAlerts:
@Jazzy-YasiauthorAug 17.2005 — Ok thanks! and sorry I didnt colour code it!
×

Success!

Help @Jazzy-Yasi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...