Page 1 of 1

Check for File selection on Submit

Posted: Mon Sep 29, 2008 7:15 am
by arunkar
Hi

Im having a upload image function. its optional so when a user submits without selecting a image it should neglect it and not process uploading it. My check fails and the page tris to upload.

Below is my image upload form page:

Code: Select all

 
<form name="Confirm" method="post" action="Itemid=395.php"  enctype="multipart/form-data" onSubmit="return check_project();">
<table width="650" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="183" class='tblTD tblBT tblBL tblBR'>Upload Project Picture</td>
            <td width="467" class='tblTD tblBT tblBR'><label><input name="vImage" type="file"></label>&nbsp;</td>
          </tr>
          <tr>
            <td colspan="2" align="center" class='tblTD'>   
            <input type="image" src='<?=$mosConfig_live_site?>/images/proj_Add.gif' alt='Add New Project' border='0' />
          </tr>
        </table>
</form>
 
This is my action page (which is the same page)

Code: Select all

 
 
if($_FILES['vImage']!="" || $_FILES['vImage']!=" " || $_POST['vImage']!="" || $_POST['vImage']!=" "){   
 
//Upload image code
 
}
 
the above check fails and when I click submit with or without the image the upload image code is executed. If there is not image I get an errors...

Any ideas how to avod this...

thanks guys

Re: Check for File selection on Submit

Posted: Mon Sep 29, 2008 7:23 am
by The_Anomaly
I don't think that "type=file" fields show up in POST. Take out the POST checks from your conditional statement, and see if it works.

I've also never used the $_FILE array as one-dimensional--so I don't know if that works or not. If the above does not work try checking for the presence of $_FILE['vImage']['tmp_name'] or something.

Re: Check for File selection on Submit

Posted: Mon Sep 29, 2008 7:25 am
by papa
You're missing a </td> after the submit button.


Shouldn't it be enough just to check the $_POST var?

Code: Select all

if(isset($_POST['vImage'])) //upload image

Re: Check for File selection on Submit

Posted: Mon Sep 29, 2008 7:37 am
by The_Anomaly
papa wrote:You're missing a </td> after the submit button.


Shouldn't it be enough just to check the $_POST var?

Code: Select all

if(isset($_POST['vImage'])) //upload image
I'm almost certain that won't work. Just now, I took one of my upload forms, and did var_dump( $_POST ) at the action page, and the file upload field did NOT show up in the POST data. So, clearly, checking for that field would fail, no matter whether it's been populated or not.

Hence, he should remove the POST checks, and only check the $_FILE array.

Re: Check for File selection on Submit

Posted: Mon Sep 29, 2008 11:43 pm
by arunkar
Thanks guys,

This did the trick, and wroked.

Code: Select all

 
    if($_FILES['vImage']['type']!=""){ 
 

this did not work though, both the cases returned false...

Code: Select all

 
   if(isset($_POST['vImage'])) //upload image
 
Also, I have another issue when I replase the existing image with another image, and while storing it with the same name. I get permission errors... but the file is uploaded.

what should I do to overcome this issue?

Warning: move_uploaded_file(/944-7762.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in

/home/testServer/development/b1g1f/worthy_cause_projects/worthy_cause_project_manage_action.php on line 150

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php3zDAsX' to '/944-7762.jpg' in

/home/testServer/development/b1g1f/worthy_cause_projects/worthy_cause_project_manage_action.php on line 150

Code: Select all

            
    move_uploaded_file ($file_tmp, "$path_big/$filename.$file_ext"); // line 150
 
The permission is 755 for folder worthy_cause_projects
The permission is 757 for folder images folder

how do I fix this? Any Ideas folks?

thanks

Re: Check for File selection on Submit

Posted: Tue Sep 30, 2008 12:22 am
by The_Anomaly
I'm not too familiar with the permission values like 757 or 755, but when I had that issue it was fixed with a little chmod tinkering. Obviously, this has some security implications...but chmod og+rw /link/to/the/folder/ . Again, I'm sure that doing that is somewhat dangerous, and perhaps you should open it only to a certain user, but that is what fixes it.