Multi File Upload help - code issues

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Multi File Upload help - code issues

Post by psurrena »

feyd | Please use

Code: Select all

and

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

and

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]
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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?
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post by psurrena »

feyd | Please use

Code: Select all

and

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

and

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]
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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.
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post 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>
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post 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">
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Hey don't mind helping but serious. please use tags.

viewtopic.php?t=21171
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post 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'); 
 		

    } 

?>
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

What does the print_r produce. and also, have you echoed the query to see what its trying to insert?
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post 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>
Post Reply