Jump to content

[SOLVED] Upload image using PHP


elviapw

Recommended Posts

Help!

 

I'm pretty new to PHP so I think I may be missing some basic concepts. I'm trying to create a form that uses PHP to allow a user to upload text and an image to a mysql database. Here is the form:

 

<!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>post</title>
    </head>
    <body>
        POST<br/><br/>
        
<form enctype="multipart/form-data" action="posted.php" method="POST">
                title:<br />  <input type="text" name="title" size="93"/> (optional)<br />
                date: <br/> <input type="text" name="date" /> (JAN 10 09)<br/>
                words:<br />   <textarea rows="50" cols="80" name="post"></textarea><br />
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
picture: <input name="userfile" type="file" /><br />
<input type="submit" value="POST DIT" />
</form>


        
    </body>
</html>

 

and here is the PHP:

 

<?php



mysql_connect("--", "--", "--", "--") or die(mysql_error()) ;
mysql_select_db("--") or die(mysql_error()) ;


$title = $_POST['title'];
$post = $_POST['post'];
$date = $_POST['date'];

$id= mysql_insert_id(); 


$imgData = addslashes ($_FILES['userfile']);
$size = getimagesize ($_FILES['userfile']);






mysql_query("INSERT INTO Posts (Title,Content,Date, image_type, image, image_size, image_name)
VALUES ('$title', '$post', '$date',  '{$size['mime']}', '$imgData', {$size[3]}', '{$_FILES['userfile']}')") ;



echo "$title $post $date $id";

?>

 

The idea is that this PHP script (which is very simple) will take the information from the form and insert in into the database. The text information works, but NONE of the image information does. I don't want to create two separate tables in PHP because I want all the text and images to be linked via the same automatic ID number. I don't think I have a problem with mysql -- the problem is with the PHP. The code returns the following error:

 

Warning: getimagesize(Array) [function.getimagesize]: failed to open stream: No such file or directory in /home/content/e/l/v/elviapw/html/posted.php on line 18

 

I have been struggling with this for weeks. Please help!

Link to comment
https://forums.phpfreaks.com/topic/147385-solved-upload-image-using-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.