Page 1 of 1
Multi File Upload help - code issues
Posted: Thu Nov 10, 2005 12:34 pm
by psurrena
feyd | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hello
I'm getting no results from the code below. It just refreshes the page but stores nothing to my database. Simply, I want it to store two images. Any help would be appreciated.
Thanks,
Peter
----
Code: Select all
<?
if(isset($_POST['upload2']))
{
$icon_name = $_FILES['userfile']['iname'];
$tmpName = $_FILES['userfile']['tmpname'];
$icon_size = $_FILES['userfile']['isize'];
$icon_type = $_FILES['userfile']['itype'];
$ad_name = $_FILES['ad_userfile']['aname'];
$tmpName = $_FILES['ad_userfile']['tmpname'];
$ad_size = $_FILES['ad_userfile']['asize'];
$ad_type = $_FILES['ad_userfile']['atype'];
$icon = $_POST['icon'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$adtitle = $_POST['adtitle'];
$adurl = $_POST['adurl'];
$adcopy = $_POST['adcopy'];
$city = $_POST['city'];
$state = $_POST['state'];
$bname = $_POST['bname'];
$bweb = $_POST['bweb'];
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
include 'library/config.php';
include 'library/opendb.php';
$query = "INSERT INTO upload2 (iname, isize, itype, icon_content, aname, asize, atype, ad_content, icon, fname, lname, email, adtitle, adurl, adcopy, city, state, bname, bweb) VALUES ('$icon_Name', '$icon_size', '$icon_type', '$icon_content', '$ad_name', '$ad_size', '$ad_type', '$ad_content', '$icon', '$fname', '$lname', '$email', '$adtitle', '$adurl', '$adcopy', '$city', '$state', '$bname', '$bweb')";
mysql_query($query) or die('Error, query failed');
include 'library/closedb.php';
header('Location: step2_image.html');
}
?>
feyd | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Thu Nov 10, 2005 1:36 pm
by hawleyjr
Try a couple things.....
Code: Select all
echo '<HR><PRE>'; print_r($_POST); echo '</PRE>';
echo '<HR><PRE>'; print_r($_FILES); echo '</PRE>';
Also, what is the enctype of the form?
Posted: Thu Nov 10, 2005 1:54 pm
by psurrena
feyd | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
I placed the code here:
....
Code: Select all
$query = "INSERT INTO upload2 (iname, isize, itype, icon_content, aname, asize, atype, ad_content, icon, fname, lname, email, adtitle, adurl, adcopy, city, state, bname, bweb) VALUES ('$icon_Name', '$icon_size', '$icon_type', '$icon_content', '$ad_name', '$ad_size', '$ad_type', '$ad_content', '$icon', '$fname', '$lname', '$email', '$adtitle', '$adurl', '$adcopy', '$city', '$state', '$bname', '$bweb')";
echo '<HR><PRE>'; print_r($_POST); echo '</PRE>';
echo '<HR><PRE>'; print_r($_FILES); echo '</PRE>';
mysql_query($query) or die('Error, query failed');
include 'library/closedb.php';
.....
Still nothing. I'm new to both PHP and MySQL so to honest, I don't know what enctype is. The form is to upload image files if that's of any help. In fact I have this code which uploads one image that works quite well:
Code: Select all
<?php
if(isset($_POST['upload']))
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$icon = $_POST['icon'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$adtitle = $_POST['adtitle'];
$adurl = $_POST['adurl'];
$adcopy = $_POST['adcopy'];
$city = $_POST['city'];
$state = $_POST['state'];
$bname = $_POST['bname'];
$bweb = $_POST['bweb'];
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
include 'library/config.php';
include 'library/opendb.php';
$query = "INSERT INTO upload (name, size, type, content, icon, fname, lname, email, adtitle, adurl, adcopy, city, state, bname, bweb, date) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$icon', '$fname', '$lname', '$email', '$adtitle', '$adurl', '$adcopy', '$city', '$state', '$bname', '$bweb', current_date)";
mysql_query($query) or die('Error, query failed');
include 'library/closedb.php';
header('Location: step2_text.html');
}
?>
feyd | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Thu Nov 10, 2005 1:57 pm
by hawleyjr
enctype is encoding type its the HTML in the form.
For uploading files it has to be:
Code: Select all
<form action="" method="get" enctype="multipart/form-data" name="myform">
Code: Select all
//Use this for testing...
echo '<HR><PRE>'; print_r($_POST); echo '</PRE>';
echo '<HR><PRE>'; print_r($_FILES); echo '</PRE>';
also, please use the PHP tags when posting.
Posted: Thu Nov 10, 2005 2:00 pm
by psurrena
<form action="" method="post" enctype="multipart/form-data" name="uploadform">
My upload button is:
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" class="box" id="userfile"></td>
Posted: Thu Nov 10, 2005 2:02 pm
by psurrena
sorry...and for the second upload button:
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="ad_userfile" type="file" class="box" id="ad_userfile">
Posted: Thu Nov 10, 2005 2:03 pm
by hawleyjr
Hey don't mind helping but serious. please use tags.
viewtopic.php?t=21171
Posted: Thu Nov 10, 2005 2:09 pm
by psurrena
My apologies. Didn't know...
Code: Select all
<?
if(isset($_POST['upload2']))
{
$icon_name = $_FILES['userfile']['iname'];
$tmpName = $_FILES['userfile']['tmpname'];
$icon_size = $_FILES['userfile']['isize'];
$icon_type = $_FILES['userfile']['itype'];
$ad_name = $_FILES['ad_userfile']['aname'];
$tmpName = $_FILES['ad_userfile']['tmpname'];
$ad_size = $_FILES['ad_userfile']['asize'];
$ad_type = $_FILES['ad_userfile']['atype'];
$icon = $_POST['icon'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$adtitle = $_POST['adtitle'];
$adurl = $_POST['adurl'];
$adcopy = $_POST['adcopy'];
$city = $_POST['city'];
$state = $_POST['state'];
$bname = $_POST['bname'];
$bweb = $_POST['bweb'];
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
include 'library/config.php';
include 'library/opendb.php';
$query = "INSERT INTO upload2 (iname, isize, itype, icon_content, aname, asize, atype, ad_content, icon, fname, lname, email, adtitle, adurl, adcopy, city, state, bname, bweb) VALUES ('$icon_Name', '$icon_size', '$icon_type', '$icon_content', '$ad_name', '$ad_size', '$ad_type', '$ad_content', '$icon', '$fname', '$lname', '$email', '$adtitle', '$adurl', '$adcopy', '$city', '$state', '$bname', '$bweb')";
echo '<HR><PRE>'; print_r($_POST); echo '</PRE>';
echo '<HR><PRE>'; print_r($_FILES); echo '</PRE>';
mysql_query($query) or die('Error, query failed');
include 'library/closedb.php';
header('Location: step2_image.html');
}
?>
Posted: Thu Nov 10, 2005 2:11 pm
by hawleyjr
What does the print_r produce. and also, have you echoed the query to see what its trying to insert?
Posted: Thu Nov 10, 2005 2:32 pm
by psurrena
Both print_r and echo do not produce anything.
Below is everything I really appreciate you time.
Code: Select all
<?php
ob_start();
?>
<html>
<head>
<title>test</title>
</head>
<body>
<?
if(isset($_POST['upload2']))
{
$icon_name = $_FILES['userfile']['iname'];
$tmpName = $_FILES['userfile']['tmpname'];
$icon_size = $_FILES['userfile']['isize'];
$icon_type = $_FILES['userfile']['itype'];
$ad_name = $_FILES['ad_userfile']['aname'];
$tmpName = $_FILES['ad_userfile']['tmpname'];
$ad_size = $_FILES['ad_userfile']['asize'];
$ad_type = $_FILES['ad_userfile']['atype'];
$icon = $_POST['icon'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$adtitle = $_POST['adtitle'];
$adurl = $_POST['adurl'];
$adcopy = $_POST['adcopy'];
$city = $_POST['city'];
$state = $_POST['state'];
$bname = $_POST['bname'];
$bweb = $_POST['bweb'];
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
include 'library/config.php';
include 'library/opendb.php';
$query = "INSERT INTO upload2 (iname, isize, itype, icon_content, aname, asize, atype, ad_content, icon, fname, lname, email, adtitle, adurl, adcopy, city, state, bname, bweb) VALUES ('$icon_Name', '$icon_size', '$icon_type', '$icon_content', '$ad_name', '$ad_size', '$ad_type', '$ad_content', '$icon', '$fname', '$lname', '$email', '$adtitle', '$adurl', '$adcopy', '$city', '$state', '$bname', '$bweb')";
echo '<HR><PRE>'; print_r($_POST); echo '</PRE>';
echo '<HR><PRE>'; print_r($_FILES); echo '</PRE>';
mysql_query($query) or die('Error, query failed');
include 'library/closedb.php';
//header('Location: step2_image.html');
echo "$icon_name";
echo "$tmpName";
echo "$icon_size";
echo "$icon_type";
echo "$ad_name";
echo "$tmpName";
echo "$ad_size";
echo "$ad_type";
echo "$icon";
echo "$fname";
echo "$lname";
echo "$email";
echo "$adtitle";
echo "$adurl";
echo "$adcopy";
echo "$city";
echo "$state";
echo "$bname";
echo "$bweb";
}
?>
<h1>test</h1>
<form action="" method="post" enctype="multipart/form-data" name="uploadform">
Upload File 1: <input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="userfile" type="file" class="box" id="userfile">
Upload file 2: <input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="ad_userfile" type="file" class="box" id="ad_userfile">
<p><b>Title / URL</b><br />
title: <input type="text" name="adtitle"><br />
URL when title is clicked: <input type="text" name="adurl" value="http://"><br />
<p><b>Copy</b><br />
Fill in the following box [keep it to 100 characters]<br />
<TEXTAREA NAME="adcopy" ROWS=10 COLS=25 maxlength="255"></TEXTAREA>
<p><b>Your Information</b><br />
First Name: <input type="text" name="fname"><br />
Last Name: <input type="text" name="lname"><br />
email: <input type="text" name="email">
<p>Business Name: <input type="text" name="bname"><br />
website: <input type="text" name="bweb" value="http://"><br />
<p>City: <input type="text" name="city"><br />
State:<input type="text" name="state" size="2" maxlength="2" />
<p>
<input name="upload" type="submit" class="box" id="upload" value=" Submit ">
</form>
</body>
</html>