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?

Member Avatar


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

Your form will need the attribute:


    <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" />


    $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(move_uploaded_file($tempfile, $absPath)) 
            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