...

View Full Version : PHP's $_FILES properties



marf
02-16-2006, 09:35 PM
I was wondering if there was a way to retrieve the FULL path of the location of the file before it is uploaded. Reason being is I have a form with lets say 3 places to input data. Two are text and one is a file. However if they forget to input text into one of the input fields, it will prompt them to insert that into the field, and what I do is i assign the value of the other field to itself, so it essentially remembers what they had typed in. However I can't seem to get the full file extension of the image they are uploading.

here is example.



<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="image">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
<table width="320" border="0" cellpadding="3" cellspacing="0" align="center">
<tr>
<td width="82">Image:</td>
<td width="9"><?php if ($errors['image']) echo '<img src="images/arrow.jpg">'; ?></td>
<td width="205"><input name="userfile" type="file" size="18" <?php if (!$errors['image_name']) echo $_FILES['userfile']; ?> /></td>
</tr>
<tr>
<td>Doc Name: </td>
<td>&nbsp;</td>
<td><input name="doc_name" type="text" size="18" maxlength="50" disabled /></td>
</tr>
<tr>
<td>Image Name:</td>
<td><?php if ($errors['image_name']) echo '<img src="images/arrow.jpg">'; ?></td>
<td><input name="image_name" type="text" size="18" maxlength="20" <? if (!$errors['image_name']) echo "value=\"".$_POST['image_name']."\""; ?> /></td>
</tr>
<tr>
<td>Description:</td>
<td><?php if ($errors['description']) echo '<img src="images/arrow.jpg">'; ?></td>
<td><input name="description" type="text" size="18" maxlength="50" <?php if (!$errors['description']) echo "value=\"".$_POST['description']."\""; ?> /></td>
</tr>
<tr>
<td colspan="3"><hr /></td>
</tr>
<tr>
<td align="center" colspan="3"><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>


Basically the main line of code is this

<?php if (!$errors['image_name']) echo $_FILES['userfile']; ?>

if they uploaded a good image.. passed my tests (I didn't include that code as it isn't necessary) I want it to remember the path of where the image was on the users local hard drive, while they correctly fill in the other fields in the form.

Any help?

Thanks in advance

fci
02-16-2006, 09:37 PM
you can use this:
http://www.codingforums.com/showpost.php?p=407982&postcount=5
but you should be doing client side validation or at least caching the uploaded file since they'd be essentially uploading the file twice with what you want to do.

marf
02-16-2006, 09:49 PM
how would i cache the file?

fci
02-16-2006, 09:52 PM
how would i cache the file?

move it to a temporary directory and contain a reference to that file via a session/cookie/db. or use JS validation to prevent it from happening (not a perfect solution but practical).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum