Jump to content

Recommended Posts

on the html form end, you just need to specify the form enctype as multipart/form-data

<form enctype="multipart/form-data" method="post">
<input name="userfile" type="userfile">
</form>

On the PHP end, this should work:

mysql_query("INSERT INTO `images` (`name`,`content`)\nVALUES ('".$_FILES[key($_FILES)]['name']."','".mysql_real_escape_string(file_get_contents($_FILES[key($_FILES)]['tmp_name']))."')");

of course, I'm just posting the filename (field name `name`) and image "content" (field name `content`) to the table `images`. Your names will be different.

Also, using $_FILES[key($_FILES)]['name'] instead of $_FILES['userfile']['name'] would allow you to include the mysql_query in a while(next($_FILES)) loop to upload multiple files (provided your form has multiple file <input>s). But it works even if you only upload one file (and doesn't care what you name the <input>.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.