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?

Member Avatar for diafol

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"
<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
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.