0

Hello,
I'm developing script php about cell phone specific, now I want to insert an uploader for image of cell phone.
I want to upload image to a fecific folder and save url to mysql table.
Can you help me to create form and how to do this?

3
Contributors
2
Replies
14
Views
4 Years
Discussion Span
Last Post by B1ts
0

Search the internet or this forum for 'upload images php' and 'save uploaded filename to mysql'

Your form will need the attribute:

enctype="multipart/form-data"
-1
<html>
<head>
</head>
<body>
<p>
    <form name="uploadImage" action="upload.php" method="post" enctype="multipart/form-data">
    <!--As diafol said, you'll need multipart/form data. It wouldn't work without that attribute-->
        Select the image:<br />
        <input type="file" name="img" />
        <input type="submit" value="Upload" />
    </form>
</p>
</body>
</html>

"upload.php":

<?php
    $myId = $_POST['id']; //Let's assume that you have an ID for every phone, or something like that. You would have a criteria.
    $tempfile=$_FILES['img']['tmp_name']; //This variable stores the temporary file.
    $defFile=$_FILES['img']['name']; //This stores the definitive file (the real path)
    if(is_uploaded_file($tempfile))
    { 
        if(move_uploaded_file($tempfile, $absPath)) 
        { 
            $relPath='imgs/'.$defFile;
            echo "<b>The image has been uploaded. Info:</b><br>";
            echo "Name: <i><a href='".$absPath."' target='_blank'>".$relPath."</a><br>";
            echo "Type: <i>".$_FILES['img']['type']."</i><br>";
            echo "Size: <i>".$_FILES['img']['size']." bytes</i><br>";
            echo "<br />";
        }
    }
    mysql_query("insert into images (path, imageCode) values ('$relPath','$myId')") or die ('Error: '.mysql_error()); //Then you do the query
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.