Jump to content

multiple file upload


myitalan

Recommended Posts

Greetings,

 

Below is the code that works uploading one image however, I need to upload 2 images (thumb and image) to the same folder every time I try to edit the code it breaks.

 

Thanks in advance.

 

<?php

 

 

$uploadDir = 'photoGallery/';

 

if(isset($_POST['upload']))

{

$fileName = $_FILES['userfile']['name'];

$tmpName = $_FILES['userfile']['tmp_name'];

$fileSize = $_FILES['userfile']['size'];

$fileType = $_FILES['userfile']['type'];

$filePath = $uploadDir . $fileName;

 

$result = move_uploaded_file($tmpName, $filePath);

if (!$result) {

                echo "Error uploading file";

                exit;

              }

 

}

 

$song = array(

    'title' => $_POST['title'],

    'description' => $_POST['description'],

    'tmb' => $filePath,

 

);

?>

 

<?

  the code then saves to an xml file.

 

$doc = new DOMDocument();

$doc->load( 'photoGallery.xml' );

 

$doc->formatOutput = true;

$r = $doc->getElementsByTagName("musiclist")->item(0);

 

$b = $doc->createElement("song");

 

$title = $doc->createElement("title");

$title->appendChild(

    $doc->createTextNode( $song["title"] )

);

$b->appendChild( $title );

 

$description = $doc->createElement("description");

$description->appendChild(

    $doc->createTextNode( $song["description"] )

);

$b->appendChild( $description );

 

$tmb = $doc->createElement("tmb");

$tmb->appendChild(

    $doc->createTextNode( $song["tmb"] )

);

 

$b->appendChild( $tmb );

 

$img = $doc->createElement("img");

$img->appendChild(

    $doc->createTextNode( $song["img"] )

);

 

$b->appendChild( $img );

 

 

$r->appendChild( $b );

   

$doc->save("photoGallery.xml");

 

    header("Location: {$_SERVER['HTTP_REFERER']}");   

?>

Link to comment
Share on other sites

thanks for the reply.  i have now taken care of that.  however I am stuck here.

 

I had this working once but after fixing other things it is now broke and i can't figure it out.

 

I am attempting to write back to my xml file through the form that has a select ins or del.

 

process php;

 

<html>

<head>

<title>Adding Images...</title>

<style type="text/css">

em {

text-align:center;

}

</style>

</head>

<body>

<p>

<?

    error_reporting(E_ALL);

ini_set( 'display_errors','1');

$doc = new DOMDocument();

 

$doc->load('photoGallery.xml');

 

 

$r = $doc->getElementsByTagName("gallery")->item(0);

 

$b = $doc->createElement("images");

$title = $doc->createElement("title");

$title->appendChild(

$doc->createTextNode($images["title"])

);

$b->appendChild( $title );

 

$description = $doc->createElement("description");

$description->appendChild(

    $doc->createTextNode( $images["description"] )

);

$b->appendChild( $description );

 

$tmb = $doc->createElement("tmb");

$tmb->appendChild(

    $doc->createTextNode( $images["tmb"] )

);

$b->appendChild( $tmb );

 

$img = $doc->createElement("img");

$img->appendChild(

    $doc->createTextNode( $images["img"] )

);

$b->appendChild( $img );

 

 

 

$r->appendChild( $b );

 

 

 

 

$doc->save("photoGallery.xml");

print "<em>imges inserted or deleted successfully :)</em><br />";

print "<a href=\"adedit.php\" title=\"return\">Return</a>";

?>

</p>

</body>

</html>

......................................

 

 

form;

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Add Songs</title>

<style type="text/css">

table {

border:1px dotted #ccc;

width:100%;

}

td {

background-color:#aaa;

color:#fff;

}

fieldset { border:0; }

label { margin-right:5px; }

 

</style>

</head>

<body>

<form action="processForm.php" method="post">

<fieldset>

<label for="title">Title:</label> <input type="text" id="title" name="title"/><br />

<label for="description">Description:</label><input type="text" id="description" name="description" /><br />

 

<select name="action">

<option value="ins">Insert</option>

<option value="del">Delete</option>

</select>

<input type="submit" />

</fieldset>

</form>

<p>Current entries:</p>

 

<ul>

<?php

 

$doc = new DOMDocument();

  $doc->load( 'photoGallery.xml' );

 

  $gallery = $doc->getElementsByTagName( "images" );

//Loop through each item

foreach ($gallery as $images) {

?>

    <li>

        <table>

            <tbody>

                <tr>

                    <td><b>Title:</b></td>

                    <td><?php echo $images->getElementsByTagName('title')->item(0)->nodeValue; ?></td>

                </tr> 

                <tr>

                    <td><b>Description:</b></td>

                    <td><?php echo $images->getElementsByTagName('description')->item(0)->nodeValue; ?></td>

                </tr>

                <tr>

                    <td><b>Image:</b></td>

                    <td><?php echo $images->getElementsByTagName('tmb')->item(0)->nodeValue; ?></td>

                </tr>

                <tr>

                    <td><b>Image:</b></td>

                    <td><?php echo $images->getElementsByTagName('img')->item(0)->nodeValue; ?></td>

                </tr>

            </tbody>

        </table>

    </li>

<?php

}

?>

</ul>

 

</body>

</html>

.........................

any idea

Link to comment
Share on other sites

... it is now broke and i can't figure it out.

a) what is broke?

b) how do you know it's broke? do you have any error reporting on?

c) where is it broke? helps with the forementioned step.

d) what have you tried?

e) please post code within

 ... 

tags.

Link to comment
Share on other sites

Greetins,

 

a) what is broke?

    adding and deleting the xml elements through the form

 

b) how do you know it's broke?

    I was able to add and deleting but had trouble displaying the xml.

 

b2) do you have any error reporting on?

 


Warning: DOMDocument::load() [domdocument.load]: XML declaration allowed only at the start of the document in /home4/southca1/public_html/saveourkidssc/photoGallery.xml, line: 142 in /home4/southca1/public_html/saveourkidssc/processForm.php on line 18

Warning: DOMDocument::load() [domdocument.load]: Extra content at the end of the document in /home4/southca1/public_html/saveourkidssc/photoGallery.xml, line: 143 in /home4/southca1/public_html/saveourkidssc/processForm.php on line 18

Notice: Undefined variable: images in /home4/southca1/public_html/saveourkidssc/processForm.php on line 26

Notice: Undefined variable: images in /home4/southca1/public_html/saveourkidssc/processForm.php on line 32

Notice: Undefined variable: images in /home4/southca1/public_html/saveourkidssc/processForm.php on line 38

Notice: Undefined variable: images in /home4/southca1/public_html/saveourkidssc/processForm.php on line 44

Fatal error: Call to a member function appendChild() on a non-object in /home4/southca1/public_html/saveourkidssc/processForm.php on line 50

 

c) where is it broke? helps with the forementioned step.

  Error printed above

 

d) what have you tried?

  different way of using dom method through phpmanual and samples

 

e) please post code within

 ... 

tags.

    Done.

 

Thanks

 

 

 

process php;

<html>
<head>
<title>Adding Images...</title>
<style type="text/css">
em {
   text-align:center;
}
</style>
</head>
<body>
<p>
<?
    error_reporting(E_ALL);
ini_set( 'display_errors','1');
$doc = new DOMDocument();

$doc->load('photoGallery.xml');


$r = $doc->getElementsByTagName("gallery")->item(0);

$b = $doc->createElement("images");
$title = $doc->createElement("title");
$title->appendChild(
$doc->createTextNode($images["title"])
);
$b->appendChild( $title );

$description = $doc->createElement("description");
$description->appendChild(
    $doc->createTextNode( $images["description"] )
);
$b->appendChild( $description );

$tmb = $doc->createElement("tmb");
$tmb->appendChild(
    $doc->createTextNode( $images["tmb"] )
);
$b->appendChild( $tmb );

$img = $doc->createElement("img");
$img->appendChild(
    $doc->createTextNode( $images["img"] )
);
$b->appendChild( $img );



$r->appendChild( $b );




$doc->save("photoGallery.xml");
print "<em>imges inserted or deleted successfully </em><br />";
print "<a href=\"adedit.php\" title=\"return\">Return</a>";
?>
</p>
</body>
</html>

......................................

 

 

form;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Add Songs</title>
<style type="text/css">
table {
   border:1px dotted #ccc;
   width:100%;
}
td {
    background-color:#aaa;
   color:#fff;
}
fieldset { border:0; }
label { margin-right:5px; }

</style>
</head>
<body>
<form action="processForm.php" method="post">
<fieldset>
<label for="title">Title:</label> <input type="text" id="title" name="title"/><br />
<label for="description">Description:</label><input type="text" id="description" name="description" /><br />

<select name="action">
<option value="ins">Insert</option>
<option value="del">Delete</option>
</select>
<input type="submit" />
</fieldset>
</form>
<p>Current entries:</p>

<ul>
<?php

$doc = new DOMDocument();
  $doc->load( 'photoGallery.xml' );

  $gallery = $doc->getElementsByTagName( "images" );
//Loop through each item
foreach ($gallery as $images) {
?>
    <li>
        <table>
            <tbody>
                <tr>
                    <td><b>Title:</b></td>
                    <td><?php echo $images->getElementsByTagName('title')->item(0)->nodeValue; ?></td>
                </tr>   
                <tr>
                    <td><b>Description:</b></td>
                    <td><?php echo $images->getElementsByTagName('description')->item(0)->nodeValue; ?></td>
                </tr>
                <tr>
                    <td><b>Image:</b></td>
                    <td><?php echo $images->getElementsByTagName('tmb')->item(0)->nodeValue; ?></td>
                </tr>
                <tr>
                    <td><b>Image:</b></td>
                    <td><?php echo $images->getElementsByTagName('img')->item(0)->nodeValue; ?></td>
                </tr>
            </tbody>
        </table>
    </li>
<?php
}
?>
</ul>

</body>
</html>

.........................

any idea

Link to comment
Share on other sites

Greetings;

 

I have resolved half the issue;

I am now able to navigate through the process however, it adds the elements tags to the xml but no data from the input form. 

 

And I'm now only getting this error

[Notice: Undefined variable: images in /home4/southca1/public_html/saveourkidssc/processForm.php on line 26

Notice: Undefined variable: images in /home4/southca1/public_html/saveourkidssc/processForm.php on line 32

Notice: Undefined variable: images in /home4/southca1/public_html/saveourkidssc/processForm.php on line 38

Notice: Undefined variable: images in /home4/southca1/public_html/saveourkidssc/processForm.php on line 44

 

any ideas

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.