This is a discussion on Upload file? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi, I would like to enable customers to upload files. How do I do that? I found following with google:'...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
I would like to enable customers to upload files. How do I do that? I found following with google:'http://www.tutorialized.com/tutorial/Simple-Form-Based-Image-Upload/792' what seems to be nice, I included it like this in my code: PHP Code:
HTML Code:
<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" onsubmit=\"return chkform()\" name=\"form\"> .... .... <td><p><input name="imagefile" type="file" size="15" maxlength="100000" accept="text/*"></p></td> .... .... </form> filetype!'...Why? I tried to upload jpeg and gif image. Thank you! -- chEErs roN I'm root, I'm allowed to do this! ;) keep on rockin' |
|
|||
|
roN wrote:
> Hi, > > I would like to enable customers to upload files. How do I do that? I > found following with > google:'http://www.tutorialized.com/tutorial/Simple-Form-Based-Image-Upload/792' > what seems to be nice, I included it like this in my code: > PHP Code:
> HTML Code:
> <form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" > onsubmit=\"return chkform()\" name=\"form\"> > ... > ... > <td><p><input name="imagefile" type="file" size="15" maxlength="100000" > accept="text/*"></p></td> > ... > ... > </form> > > filetype!'...Why? I tried to upload jpeg and gif image. Thank you! hm and there's nothing passed when I'm gonna check like: echo $HTTP_POST_FILES ['imagefile']['name']."<br>\n"; here's just nothing, why not? -- chEErs roN I'm root, I'm allowed to do this! ;) keep on rockin' |
|
|||
|
Hi,
You must use the following in your <form ...> tag enctype="multipart/form-data" <form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" onsubmit=\"return chkform()\" name=\"form\" enctype="multipart/form-data"> This is used to tell your browser the POST include image file not only text. Hopes this help. Danny Wong "roN" <NOspam@example.com> ???????:43t3grF1oholrU5@individual.net... > roN wrote: > >> Hi, >> >> I would like to enable customers to upload files. How do I do that? I >> found following with >> > google:'http://www.tutorialized.com/tutorial/Simple-Form-Based-Image-Upload/792' >> what seems to be nice, I included it like this in my code: >> PHP Code:
>> HTML Code:
>> <form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" >> onsubmit=\"return chkform()\" name=\"form\"> >> ... >> ... >> <td><p><input name="imagefile" type="file" size="15" maxlength="100000" >> accept="text/*"></p></td> >> ... >> ... >> </form> >> >> filetype!'...Why? I tried to upload jpeg and gif image. Thank you! > > hm and there's nothing passed when I'm gonna check like: > echo $HTTP_POST_FILES ['imagefile']['name']."<br>\n"; > here's just nothing, why not? > > -- > chEErs roN > > I'm root, I'm allowed to do this! ;) > keep on rockin' |
|
|||
|
To summarize, you need a form tag like so:
<form enctype="multipart/form-data" method="post" action="upload.php"> <input type="file" name="uploadfile"> AND in your upload php script you should not just use "copy()"... in case the file was injected to your server, check documentation on: is_uploaded_file and move_uploaded_file |
|
|||
|
Ken Chau wrote:
> To summarize, you need a form tag like so: > > <form enctype="multipart/form-data" method="post" action="upload.php"> > <input type="file" name="uploadfile"> > > AND in your upload php script you should not just use "copy()"... in > case the file was injected to your server, check documentation on: > > is_uploaded_file and move_uploaded_file yup, thank you guys, erm how can I return the whole image-path? like exactly the String that was entered in the input field? or let's say it like that: I get all the POST data from that form, I'm gonna print these so the customer can verify all the data, then he's gonna press another button to add these data to the DB or he can go back and correct the data, I'm now doin it like: PHP Code:
that? I have no idea... Or does anybody know another approach? Thank you for hints and suggestions! -- chEErs roN I'm root, I'm allowed to do this! ;) keep on rockin' |
|
|||
|
I've not heard of people doing what you're doing quite exactly - the
whole verification before uploading. It's an interesting idea... the problem you have is that the path selected from the previous form will not be preserved. You might as well make the upload happen on the SECOND step. Or... you'll have to do this: 1. upload on the first step 2. save the information about the temp file path & name + the real name of the file (put in form) 3. move the file from tmp location to a dedicated pool of your own temp location 4. after the second step's submission, move the file to the real location a bit clumsy... i suppose you could come up with some other clever form of upload interface (I sometimes use a popup window)... or you can be clever and use an AJAX upload thing. ----------- Ken Chau http://www.gizzar.com |