File input field

Does anybogy know how to echo a vlaue in a file input field

I’ve tried

<input type"file" name=“something” value=“something”>

This doent work

dosn’t work.

it’s a securety feature, otherwise anybody could enter a value like C:Program Filesany aplicationpasworts.xml, then hide the filed and make u submit this without the person knowing it.

it’s very good that it’s not working anymore.

The reason for me asking I have a file upload page, obviously, where users can upload 6 images. Now if they want to change 1 image out of the 6 they have to set the values of all 6.

I cant do the if set because when the images are uploaded they are renamed before they are saved into a specific directory.

Do you know of a way around this.

im haven’t realy understood why u wanna change the other inpu fiels if the are changing one of them. could u explain that again.

You can view the page here

http://www.sunseekerrentals.co.uk/users/update_images.php?list_id=0000004

Now if I want to change one of the images. When I click the upload button the fields for the other 5 images are blank, so dont get a value.

As the script over writes the other images stored you lose everything not given a value

I am not fully sure I understand what you are trying to accomplish here, but here are somethings I can tell you.

<input type=“file” - These cannot be auto filled. As with a normal text field you can use value=“blah” and it will fill it in, which is useful for error checking in forms and keeping the data that was previously entered.

This is because it is tied into the file system of the clients machine and would lead to huge security risk if it was allowed.

I don’t know if this helps, I doubt it will, but you can check for empty values by using empty().

i can’t. no login. do u have a dummy/testing accout?
ur registration js isn’t working right. i putts out an error for a missing password, although i entered one. Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.6) Gecko/20070723 Iceweasel/2.0.0.6 (Debian-2.0.0.6-0etch1)

u shouldnt let the user upload all images again. u may check whether a new file has been uploded and overwrite just these images.

Heres the code so you can see where i am at the moment, its working fine.

[php]

<?php if (file_exists("../uploads/".$curr_Property."")) { $numoffile = 6; $file_dir = "../uploads/".$curr_Property."/"; if($_POST['upload']) { # edit # $maxwidth = 350; $maxheight = 250; $max_filesize = 102400; $types_array = array('image/pjpeg'); # end edit # for ($i=0; $i < $numoffile; $i++) { if($_FILES['image']['name'][$i] == "") { echo "Please select a file to upload!n"; exit; } if(!in_array($_FILES['image']['type'][$i], $types_array)) { echo "That file type is not allowed!!. You can only upload image files with JPG extensions.n"; exit; } $max_filesize_kb = ($max_filesize / 1024); if($_FILES['image']['size'][$i] > $max_filesize) { echo "You file is too large, files may be up to ".$max_filesize_kb."kbn"; exit; } $imagesize = getimagesize($_FILES['image']['tmp_name']); $imagewidth = $imagesize[0]; $imageheight = $imagesize[1]; if($imagewidth > $maxwidth || $imageheight > $maxheight) { echo "You file is too large, files may be up to ".$maxwidth."px x ".$maxheight."px in sizen"; exit; } if (trim($_FILES['image']['name'][$i]) != "") { $newfile = $file_dir . "$i.jpg"; move_uploaded_file($_FILES['image']['tmp_name'][$i], $newfile); $j++; } } } ?>
<?php for($i=0; $i < $numoffile; $i++) { ?>

<?php }

?>



<?php } else { mkdir("../uploads/".$curr_Property."", 0777);

$numoffile = 6;
$file_dir = “…/uploads/”.$curr_Property."/";
if($_POST[‘upload’])
{

edit

$maxwidth = 350; 
$maxheight = 250; 
$max_filesize = 102400; 

$types_array = array('image/pjpeg'); 

end edit

for ($i=0; $i < $numoffile; $i++)
{
if($_FILES[‘image’][‘name’][$i] == “”)
{
echo “Please select a file to upload!n”;
exit;
}

if(!in_array($_FILES[‘image’][‘type’][$i], $types_array))
{
echo “That file type is not allowed!!. You can only upload image files with JPGextensions.n”;
exit;
}

$max_filesize_kb = ($max_filesize / 1024); 

if($_FILES[‘image’][‘size’][$i] > $max_filesize)
{
echo "You file is too large, files may be up to ".$max_filesize_kb.“kbn”;
exit;
}

$imagesize = getimagesize($_FILES['image']['tmp_name']); 

$imagewidth = $imagesize[0]; 
$imageheight = $imagesize[1]; 

if($imagewidth > $maxwidth || $imageheight > $maxheight)
{
echo "You file is too large, files may be up to ".$maxwidth."px x ".$maxheight.“px in sizen”;
exit;
}

       if (trim($_FILES['image']['name'][$i]) != "") 
       { 
             $newfile = $file_dir . "$i.jpg"; 
             move_uploaded_file($_FILES['image']['tmp_name'][$i], $newfile); 
             $j++; 
       } 

 } 

}

?>

<?php for($i=0; $i < $numoffile; $i++) { ?>

<?php } ?>
<?php } ?>

[/php]

The error while trying to register was I had the confirm password field checking the surname field for some reason. :oops:

what happens if u just delete these lines:
[php]if($_FILES[‘image’][‘name’][$i] == “”)
{
echo “Please select a file to upload!n”;
exit;
}[/php]

should work.

btw i guess u should use continue; instead of exit;. that way i doesn’t stop on error, but compleates the upload of the other images.

You only get 1 box and the file is uploaded as 0.jpg irrespective of whether is 1 - 5.jpg your trying to change

what do u mean with “You only get 1 box”?

one more thing:

[php]if (trim($_FILES[‘image’][‘name’][$i]) != “”)[/php]
isn’t a good way to find out whether a file was uploaded

use
[php]if ($_FILES[‘image’][‘error’][$i] == UPLOAD_ERR_OK)[/php]
instead

Sorry

You get all boxes but when you click upload you get

That file type is not allowed!!. You can only upload image files with JPG extensions

I dont want to delete this because it verifies the files uploaded are jpg

in this case don’t delete it but replace it with:
[php]if($_FILES[‘image’][‘error’][$i] == UPLOAD_ERR_NO_FILE)
{
continue;
}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service