Digital Wallfare Posted December 5, 2009 Share Posted December 5, 2009 Hi all, I'm trying to find a way to upload images to a folder on my server whilst maintaining its link to the row of data in the table that was entered with the image Eg -Row 1 MerchantName, MerchantType, Image link Row 2 MerchantName, MerchantType, Image link etc.. Then I need to recall the data and the related image back into a looping table of search results. eg: --------------------|--------------------------------------------------------------------- | Merchant Name | | Merchant Type Image | | Address | | Detals --------------------|---------------------------------------------------------------- (I have the table coded already using $row_details. And i thought that would work for image links but it doesnt) Would anyone be able to talk me through this or point me in the direction of tutorials (or even just tall me what these 2 functions are called so i can google search them)? Sam Quote Link to comment https://forums.phpfreaks.com/topic/184112-complicated-image-upload-and-retrieve-problem/ Share on other sites More sharing options...
Zane Posted December 5, 2009 Share Posted December 5, 2009 You need the move_uploaded_file function. CLICK THE LINK.. and view the example for the best explanation. you control where the image goes on your server.. therefore you control what the image link will be, there's nothing dynamic other than the filename. Other than that it's nothing different that INSERTing that link into the table column. Moreover, if you really want some efficient help. Post the code you are currently using. Quote Link to comment https://forums.phpfreaks.com/topic/184112-complicated-image-upload-and-retrieve-problem/#findComment-972044 Share on other sites More sharing options...
Digital Wallfare Posted December 5, 2009 Author Share Posted December 5, 2009 Zanus, Thanks for the reply, I will go read up on that now. As for not posting the code, I would but i dont have any that pertains to this question. I could post the table echo i have an thats the only bit that links this question in to the rest of the site. If you get what i mean. here it is: <table> <tr> <td width="200" align="left" rowspan="8"><img src = '.$row_details['Image'].'" /></td> </tr> <tr> <td width="100" height="27" align="left"><b>Name:</b></td> <td width="400" align="left">'.$row_details['MerchantName'].'</td> </tr> <tr> <td width="100" height="27" align="left"><b>Address 1:</b></td> <td width="400" align="left"> '.$row_details['AddressLine1'].'</td> </tr> <tr> <td width="100" height="27" align="left"><b>Address 2:</b></td> <td width="400" align="left"> '.$row_details['AddressLine2'].'</td> </tr> <tr> <td width="100" height="27" align="left"><b>Town/City:</b></td> <td width="400" align="left"> '.$row_details['TownCity'].'</td> </tr> <tr> <td width="100" height="27" align="left"><b>Telephone:</b></td> <td width="400" align="left"> '.$row_details['Telephone'].'</td> </tr> <tr> <td width="100" height="27" align="left"><b>Website:</b> </td> <td width="400" align="left">'.$row_details['Website'].'</td> </tr> <tr> <td width="100" height="27" align="left"><b>Description:</b> </td > <td width="400" align="left">'.$row_details['Description'].'</td> </tr> </table><br />'; This question is mainly a fact finding mission to establish what the function/methods are called and how they operate. I will read up on what you suggested and have a go at some code, which if i have a problem with , you can be sure i'll be back here Thanks again, Sam Quote Link to comment https://forums.phpfreaks.com/topic/184112-complicated-image-upload-and-retrieve-problem/#findComment-972051 Share on other sites More sharing options...
Digital Wallfare Posted December 5, 2009 Author Share Posted December 5, 2009 Ok, i went away and read up on how to based on Zanus' Information. I've have the image uploading fine, both to the table row and to the images folder. There is one problem- The code I thank should display the image, doesn't. Can anyone help on this? here is my upload php - $connection = mysql_connect($hostname, $username, $password); if (!$connection) { die("A connection to the server could not be established"); } //remember to select the database! mysql_select_db($database) or die("Database could not be selected!"); //This is the directory where images will be saved $target = "images/"; $target = $target . basename( $_FILES['Image']['name']); //get the values from the form $MerchantName = $_POST["MerchantName"]; $MerchantType = $_POST["MerchantType"]; $customerID = $_POST["customerID"]; $AddressLine1 = $_POST["AddressLine1"]; $AddressLine2 = $_POST["AddressLine2"]; $TownCity = $_POST["TownCity"]; $County = $_POST["County"]; $Telephone = $_POST["Telephone"]; $Website = $_POST["Website"]; $Description = $_POST["Description"]; $Image=($_FILES['Image']['name']); $query = "INSERT INTO $tablename (MerchantName,MerchantType,AddressLine1,AddressLine2,TownCity,County,Telephone,Website,Description,Image) VALUES ('$MerchantName', '$MerchantType', '$AddressLine1', '$AddressLine2', '$TownCity', '$County', '$Telephone', '$Website', '$Description', '$Image')"; $result = mysql_query($query); if (!$result) { die("Merchant not added, please check the details have been entered correctly"); } //Writes the photo to the server if(move_uploaded_file($_FILES['Image']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } echo 'Merchant added succesfully. <br /> <FORM METHOD="LINK" ACTION="admin.php"> <INPUT TYPE="submit" VALUE="Back to Admin Page"> </FORM>' ?> and here is the looping table that i want the images displayed in: while ($row_details = mysql_fetch_array($result)) { echo ' <table> <tr> <td width="200" align="left" rowspan="8"><img src = '.$row_details['Image'].'" /></td> </tr> <tr> <td width="100" height="27" align="left"><b>Name:</b></td> <td width="400" align="left">'.$row_details['MerchantName'].'</td> </tr> <tr> <td width="100" height="27" align="left"><b>Address 1:</b></td> <td width="400" align="left"> '.$row_details['AddressLine1'].'</td> </tr> <tr> <td width="100" height="27" align="left"><b>Address 2:</b></td> <td width="400" align="left"> '.$row_details['AddressLine2'].'</td> </tr> <tr> <td width="100" height="27" align="left"><b>Town/City:</b></td> <td width="400" align="left"> '.$row_details['TownCity'].'</td> </tr> <tr> <td width="100" height="27" align="left"><b>Telephone:</b></td> <td width="400" align="left"> '.$row_details['Telephone'].'</td> </tr> <tr> <td width="100" height="27" align="left"><b>Website:</b> </td> <td width="400" align="left">'.$row_details['Website'].'</td> </tr> <tr> <td width="100" height="27" align="left"><b>Description:</b> </td > <td width="400" align="left">'.$row_details['Description'].'</td> </tr> </table><br />'; } Can somebody help me? it's probably me using the wrong function in the table (that's my hunch) but i dont know what the proper function for recalling image link/data is. Thanks, Sam Quote Link to comment https://forums.phpfreaks.com/topic/184112-complicated-image-upload-and-retrieve-problem/#findComment-972082 Share on other sites More sharing options...
Zane Posted December 5, 2009 Share Posted December 5, 2009 You're going about it just fine.. it's just you forgot to use the variable you created. $target //This is the directory where images will be saved $target = "images/"; $target = $target . basename( $_FILES['Image']['name']); //get the values from the form $Image=($_FILES['Image']['name']); // Wouldn't it be more logical to make $image = $target...? In fact.. Why even reassign $target to a new variable..? It would be the same as this INSERT INTO $tablename (MerchantName,MerchantType,AddressLine1,AddressLine2,TownCity,County,Telephone,Website,Description,Image) VALUES ('$MerchantName', '$MerchantType', '$AddressLine1', '$AddressLine2', '$TownCity', '$County', '$Telephone', '$Website', '$Description', '$target') Instead you are essentially doing this INSERT INTO $tablename (MerchantName,MerchantType,AddressLine1,AddressLine2,TownCity,County,Telephone,Website,Description,Image) VALUES ('$MerchantName', '$MerchantType', '$AddressLine1', '$AddressLine2', '$TownCity', '$County', '$Telephone', '$Website', '$Description', '$_FILES['Image']['name']') Quote Link to comment https://forums.phpfreaks.com/topic/184112-complicated-image-upload-and-retrieve-problem/#findComment-972090 Share on other sites More sharing options...
Digital Wallfare Posted December 5, 2009 Author Share Posted December 5, 2009 Ok I changed that but the image is still not displaying in the search results table i posted above. Quote Link to comment https://forums.phpfreaks.com/topic/184112-complicated-image-upload-and-retrieve-problem/#findComment-972128 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.