[SOLVED] Trying to figure out an upload script

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
Seona
Forum Commoner
Posts: 33
Joined: Wed Dec 08, 2004 11:04 pm

[SOLVED] Trying to figure out an upload script

Post by Seona »

Hi guys,

I have a form that allows the site's owners to upload image files and associate them with entries in the database. I have the database side of things working: the file path is stripped down and added to the database so that it can be used to refernece the file in the output page. Now I'm stuck on the bit where I actually upload the files.

I have the following form:

Code: Select all

<form action="act_editCategory.php" method="post" name="editCategoryForm" id="editCategoryForm">
            <input type="hidden" name="ID" value="<?php print $row&#1111;"ID"]; ?>" />
            <label for="CategoryName">Category Name:</label>
            <input name="CategoryName" type="text" id="CategoryName" value="<?php print $row&#1111;"CategoryName"]; ?>" />
            <label for="Image">Title Image:</label>
            <input name="Image" type="file" id="Image" />
            <label for="Image1">Image 1:</label>
            <input name="Image1" type="file" id="Image1" />
            <label for="Image2">Image 2:</label>
            <input name="Image2" type="file" id="Image2" />
            <input type="submit" value="Edit Category" />
</form>
In the processing page, I currently have the following code:

Code: Select all

$path1 = "/var/www/html/_images/db_titles/" . $_FILES&#1111;'Image']&#1111;'name'];
if (is_uploaded_file($_FILES&#1111;'Image']&#1111;'name'])) &#123;
	  move_uploaded_file($_FILES&#1111;'Image']&#1111;'tmp_name'], $path1);
&#125;
Theoretically, and certainly going by other things I've read online, this ought to be uploading the file. I got the file path from my FTP program - that's where it says the folder lives - but I'm still not sure if this is correct. At any rate, the file that I tried to pass through the first file field is not being uploaded.

Can someone please tell me what I'm doing wrong? I've tried numerous upload scripts from different sources, and can't get any of them to work.

Cheers,

Seona.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

is_uploaded_file() should be called with the tmp_name..

the name element of the array should hold the original filename it had.
Seona
Forum Commoner
Posts: 33
Joined: Wed Dec 08, 2004 11:04 pm

Post by Seona »

Well, I've made that change:

Code: Select all

$path1 = "/var/www/html/_images/db_titles/" . $_FILES&#1111;'Image']&#1111;'name'];
	if (is_uploaded_file($_FILES&#1111;'Image']&#1111;'tmp_name'])) &#123;
	  move_uploaded_file($_FILES&#1111;'Image']&#1111;'tmp_name'], $path1);
	&#125;
Still no joy. :( Any other suggestions?

Is it likely to matter that I'm doing other things first in the script? Does the file thing have to come first or something?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the enctype of the form post needs to be: multipart/form-data

http://us3.php.net/manual/en/features.file-upload.php

the example there shows what a form should look like.
Seona
Forum Commoner
Posts: 33
Joined: Wed Dec 08, 2004 11:04 pm

Post by Seona »

Woohoo! That was what was missing. :)

Thank you once again for your help. :)
Post Reply