Page 1 of 1

[SOLVED] Trying to figure out an upload script

Posted: Tue Jan 11, 2005 9:15 pm
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.

Posted: Tue Jan 11, 2005 9:18 pm
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.

Posted: Tue Jan 11, 2005 9:32 pm
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?

Posted: Tue Jan 11, 2005 9:42 pm
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.

Posted: Tue Jan 11, 2005 9:57 pm
by Seona
Woohoo! That was what was missing. :)

Thank you once again for your help. :)