-1

I am trying now to upload image into folder(images) and display filepath into table column to reference uploaded image. (example) image uploaded:(report.jpg) store image into folder(images) now create URL to image in table < img src="https://www.****.com/images/report.jpg" alt="" /> unfortunatley i have come up with which only stores the filename in the table (report.jpg)

<?php

if ($_POST["action"] == "Load") {
    $folder = "images/";
    move_uploaded_file($_FILES["filep"]["tmp_name"], "$folder".$_FILES["filep"]["name"]);

    echo "<p align=center>File ".$_FILES["filep"]["name"]."loaded...";

    $result = mysql_connect("**", "**", "**") or die ("Could not save image name Error: " . mysql_error());
    mysql_select_db("testing") or die("Could not select database");
    mysql_query("INSERT into links (hyper_links) VALUES('".$_FILES['filep']['name']."')");

    if ($result) { 
        echo "Image name saved into database";
    } else {
        //Gives and error if its not
        echo "Sorry, there was a problem uploading your file.";
    }
}
?>
<form action=sample.php method=post enctype="multipart/form-data">
    <table border="0" cellspacing="0" align=center cellpadding="3" bordercolor="#cccccc">
        <tr>
            <td>File:</td>
            <td><input type="file" name="filep" size=45/></td>
        </tr>
        <tr>
            <td colspan=2>
                <p align=center>
                    <input type=submit name=action value="Load"/>
                </p>
            </td>
        </tr>
    </table>
</form>
INOH
  • 365
  • 2
  • 9
  • 27
  • Have a look at my answer to this question: [Full Secure Image Upload Script](http://stackoverflow.com/questions/38509334/full-secure-image-upload-script/38712921#38712921) Just follow it through. You'll learn quite a bit about security and image upload scripts and you'll have a fully functional script at the end. – icecub Aug 12 '16 at 15:35
  • thanks for the help, i have edited my question above to show you what i am trying to output to column(hyper_links), the reason being is that i am using Navicat to load database and displaying the links so i can view from inside Navicat. (loading images into database was just taking up so much time and size, so i decided to try loading URLs – INOH Aug 12 '16 at 15:57
  • if the path to the images never changes then all you need to record in the db is the filename rather than the full url because you can then generate the path at runtime – Professor Abronsius Aug 12 '16 at 16:02
  • When i load mysql database into Navicat, i can click the < img src="https://*******/images/report.jpg" alt="" /> and it will display the file below in a window, so i need to have the full link as above displayed to be able to direct the browser. sorry if maybe i am misunderstanding your comment – INOH Aug 12 '16 at 16:07

1 Answers1

1

Try Below Code.

NOTE:- Change http://www.yourwebsite.com with your website name in code.

<?php

if ($_POST["action"] == "Load") {
    $folder = "images/";
    move_uploaded_file($_FILES["filep"]["tmp_name"], "$folder".$_FILES["filep"]["name"]);

    echo "<p align=center>File ".$_FILES["filep"]["name"]."loaded...";

    $result = mysql_connect("**", "**", "**") or die ("Could not save image name Error: " . mysql_error());
    mysql_select_db("testing") or die("Could not select database");
    mysql_query("INSERT into links (hyper_links) VALUES('https://www.yourwebsite.com/images/".$_FILES['filep']['name']."')");

    if ($result) { 
        echo "Image name saved into database";
    } else {
        //Gives and error if its not
        echo "Sorry, there was a problem uploading your file.";
    }
}
?>

This will add - http://www.yourwebsite.com/images/report.jpg in your table

Rahul Mukati
  • 744
  • 2
  • 10
  • 15
  • thanks that is great, how can i now add the before and after the web address – INOH Aug 13 '16 at 04:54
  • Sorry took so long, i have managed to figure this out here is the code below `$a = ('" alt="" />');` `$sql = ("INSERT into links (hyper_links) VALUES(' – INOH Aug 24 '16 at 17:51