fry2010 Posted May 4, 2009 Share Posted May 4, 2009 Im not sure if this is really the right place for it. Basically im trying to specify the actuall path of an uploaded file. So basically the user is filling out a form, and they upload an image. Lets say the form has errors in it. At the moment I have it so that it will tell them what errors were made when they submit it. It will show them the form again but with the correct values already stored in the fields so they dont end up typing it out again. I would like to get this to work for the file upload field aswell. I have tried the following: <?php $img_file = $_FILES['img']; // DO FILE CHECKS ETC.... // THERE WAS AN ERROR IN THE FORM, BUT THE FILE UPLOAD WAS OK... if($error) { if(!$img_file_error) { ?> <input type="file" name="img" <?php echo 'value="'.$img_file['tmp_name'].'"; ?>> <?php } ?> So what I have tried to do is the same as you would do on a normal text field, by setting the value="" to what I want inside that field. But this doesnt work with type="file" fields. Is there another attribute that I can specify the directory that the user submits? I no it can be done with js, but this form is for people who dont have js enabled. Anyone have any ideas? Link to comment https://forums.phpfreaks.com/topic/156748-setting-file-upload-directory/ Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 $_FILES['img']['name']? Link to comment https://forums.phpfreaks.com/topic/156748-setting-file-upload-directory/#findComment-825403 Share on other sites More sharing options...
fry2010 Posted May 4, 2009 Author Share Posted May 4, 2009 yeah I tried that too, unfortunatly its the same thing. I have echoed out the values that $_FILES['img']['name'] and they have the correct text, its just not putting it inside the field. Should it be doing so then? Link to comment https://forums.phpfreaks.com/topic/156748-setting-file-upload-directory/#findComment-825414 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Are you aware there is an unterminated string in your echo? Link to comment https://forums.phpfreaks.com/topic/156748-setting-file-upload-directory/#findComment-825416 Share on other sites More sharing options...
fry2010 Posted May 4, 2009 Author Share Posted May 4, 2009 oh yeah that happened aswell, but I sorted that out. Dont no how you spotted it though without having an error thrown at you lol. Its there just because I hand typed that just now, so didnt check with that. Link to comment https://forums.phpfreaks.com/topic/156748-setting-file-upload-directory/#findComment-825418 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Did that fix it? Link to comment https://forums.phpfreaks.com/topic/156748-setting-file-upload-directory/#findComment-825420 Share on other sites More sharing options...
fry2010 Posted May 4, 2009 Author Share Posted May 4, 2009 No no.. that happened ages ago, its stil not happening. Infact I have checked the source code and it shows that its in the value="" field as: value="C:\WINDOWS\Temp\php1E1.tmp" Thats for ['tmp_name'] and for ['name'] it is: value="Sample.jpg" and that is in the actual HTML source code, so I imagine you cant use value="" to specify what you want inside the file type... Link to comment https://forums.phpfreaks.com/topic/156748-setting-file-upload-directory/#findComment-825426 Share on other sites More sharing options...
mapleleaf Posted May 4, 2009 Share Posted May 4, 2009 This looks like your problem: <input type="file" name="img" <?php echo 'value="'.$img_file['tmp_name']."; ?>> you can't do that as far as I know Link to comment https://forums.phpfreaks.com/topic/156748-setting-file-upload-directory/#findComment-825427 Share on other sites More sharing options...
fry2010 Posted May 4, 2009 Author Share Posted May 4, 2009 You mean that you cant use a value="" field to specify what you want inside a type="file"? or that my code had a delimeter missing? it should have been like this, i just made a typo ignore that: <input type="file" name="img" <?php echo 'value="'.$img_file['tmp_name'].'"'; ?>> Link to comment https://forums.phpfreaks.com/topic/156748-setting-file-upload-directory/#findComment-825430 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 <input type="file" name="img" <?php echo 'value="'.$img_file['tmp_name'].'"'; ?> /> Link to comment https://forums.phpfreaks.com/topic/156748-setting-file-upload-directory/#findComment-825431 Share on other sites More sharing options...
fry2010 Posted May 4, 2009 Author Share Posted May 4, 2009 No not that either, I missed that out aswell lol, iv been trying to do valid html since reading another article about it. Here is the exact output from my browsers source code: <?php <div> <label for="main_img" >Main Image: (This will be visible as part of your listing, outside your main page. We recommend an image size of around 800px on the longest side.)</label> <input type="file" name="main_img" value="C:\WINDOWS\Temp\php1E8.tmp" /> ?> And in my actuall form field for the "main_img" field it is blank, no text at all... I really appreciate ur guys help in this. Link to comment https://forums.phpfreaks.com/topic/156748-setting-file-upload-directory/#findComment-825433 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 From Google, I read that it's not possible due to security issues. Link to comment https://forums.phpfreaks.com/topic/156748-setting-file-upload-directory/#findComment-825438 Share on other sites More sharing options...
fry2010 Posted May 4, 2009 Author Share Posted May 4, 2009 oh rite, that explains it then. However, I have come accross a site that actually keeps the value of the file upload inside it when you do a page refresh. I have switched javascript off and it still works?? I wonder how he did it? http://www.elated.com/articles/html-forms--hidden-fields-password-fields-and-file-upload-fields/ At the bottom there is a file upload field, and putting a file in there and then refreshing with js turned off it still remains there.. Link to comment https://forums.phpfreaks.com/topic/156748-setting-file-upload-directory/#findComment-825441 Share on other sites More sharing options...
PFMaBiSmAd Posted May 4, 2009 Share Posted May 4, 2009 That's because it is the browser keeping the value in the field on a page refresh. The only way to put a value in a file field is by using the browser's file selection dialog box. HTML and javascript cannot put a value in. Link to comment https://forums.phpfreaks.com/topic/156748-setting-file-upload-directory/#findComment-825624 Share on other sites More sharing options...
fry2010 Posted May 4, 2009 Author Share Posted May 4, 2009 Oh right. I thought I read somewhere about javascript being able to do so... Probably not exactly what I was looking for though I just skimmed it because it was js. I suppose the only real option I have is if the file validates, just place it underneath the file input box to show they already have it loaded. It will save them the hassle of having to search their files again. Thanks for the help ken, PFMa...., and maple. Link to comment https://forums.phpfreaks.com/topic/156748-setting-file-upload-directory/#findComment-825852 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Yeah I agree PFMaBiSmAd is such a long and hard name to spell. I have no idea how he manages to spell that every time logging in. Link to comment https://forums.phpfreaks.com/topic/156748-setting-file-upload-directory/#findComment-825856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.