Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Inserting image link into db

Posted on 2007-03-23
24
Medium Priority
?
288 Views
Last Modified: 2008-01-09
What is the best and easiest way to insert an image's link into the db and then call it onto the page?
0
Comment
Question by:pingeyeg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 16
  • 6
  • 2
24 Comments
 
LVL 14

Expert Comment

by:Vel Eous
ID: 18781731
Into DB:

$url = addslashes($_POST['inputField']);


Out of DB:

$url = stripslashes(("SELECT url FROM table"));

echo $url;
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18782352
I thought that seemed too easy.  Doesn't seem to do anything.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18782360
What I'm doing is using a form that has a file select button to add the image link to the database.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Expert Comment

by:sebastienbo
ID: 18782529
hmm, strange

what do you wanna put excly in the DB ? the image itself of the local path that the user has created by pushing the browse button (the latter doesn't make sense to do)
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18782560
I want to place the link of where the image is located on the server into the database and then be able to retrieve it by using something like:

<img src="<?= strImage?>">
0
 
LVL 5

Accepted Solution

by:
sebastienbo earned 800 total points
ID: 18782643
wll understand correctly, that by doing so, you will have a local path: c:\path\to\image.jpg , in order for this to work with the img tag, only the uploader will be able to see this image, as the image will be localy by the user who has uploaded the link.

On this page :
http://www.tizag.com/phpT/fileupload.php

You have an example of how to upload an image, but what you need to do is not copying the file to somewhere but just copy the path + filename called $_FILES['uploadedfile']['name'] in the example, right to your DB , the DB field will contain only the name and path of the localy located file
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18783159
From what I read I was able to come up with this, but it doesn't seem to work correctly unless I am missing something:

$target_path = "mockup/images/";
$target_path = $target_path . basename( $_FILES['strImage']['name']);

addslashes($strOtherservices);
addslashes($strServicesoffered);
addslashes($strProvidertagline);

$SQL = mysql_query("SELECT * FROM tblAdspace where strCompanyname = '" .$strCompanyname. "'")
or die(mysql_error());

if ($row = mysql_fetch_array($SQL)) {

$SQL = mysql_query("UPDATE tblAdspace SET "
       . "strProviderservice = '" . $strProviderservice . "', "
     . "strCompanyname='" . $strCompanyname . "', "
     . "strOwner='" . $strOwner . "', "
       . "strAddress='" . $strAddress . "', "
     . "strTown='" . $strTown . "', "
       . "strZipcode='" . $strZipcode . "', "
       . "strPhone='" . $strPhone . "', "
     . "str2ndphone='" . $str2ndphone . "', "
     . "strMobile='" . $strMobile . "', "
     . "strPager='" . $strPager . "', "
     . "strFax='" . $strFax . "', "
     . "strEmail='" . $strEmail . "', "
     . "strWebsite='" . $strWebsite . "', "
     . "strLicense='" . $strLicense . "', "
     . "strInsured='" . $strInsured . "', "
     . "strBonded='" . $strBonded . "', "
     . "strHours='" . $strHours . "', "
     . "str24houremerg='" . $str24houremerg . "', "
     . "strOtherservices='" . $strOtherservices . "', "
     . "strServicearea='" . $strServicearea . "', "
     . "strInbusiness_since='" . $strInbusiness_since . "', "
     . "strServicesoffered='" . $strServicesoffered . "', "
       . "strFreeestimate='" . $strFreeestimate . "', "
     . "strWorkguaranteed='" . $strWorkguaranteed . "', "
       . "strProvidertagline='" . $strProvidertagline . "', "
     . "strAd_size='" . $strAd_size . "', "
       . move_uploaded_file($_FILES['strImage']['tmp_name'], $target_path);
     . " WHERE strCompanyname = '" . $strCompanyname . "'");
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18783275
Any ideas?
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18783309
Right now these are the errors that I am getting:

Warning: move_uploaded_file(/Library/WebServer/Documents/images/plumber_premium.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /Library/WebServer/Documents/admin/update_provider.php on line 75

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/var/tmp/phpOq5GrV' to '/Library/WebServer/Documents/images/plumber_premium.jpg' in /Library/WebServer/Documents/admin/update_provider.php on line 75
0
 
LVL 14

Assisted Solution

by:Vel Eous
Vel Eous earned 1200 total points
ID: 18783338
Have you set the CHMOD value of the folder you are uploading the files into to '777' ?
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18783409
I just tried that, but it still gives me the same error
0
 
LVL 14

Expert Comment

by:Vel Eous
ID: 18783422
What is on line 75 of your update_provider.php file and what lines above that does it access ?
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18783431
Ok, I finally got the permission issue fixed, but still the image's link isn't being sent into the db.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18783461
I don't know what I have done now, but I can't view my website now that I have tampered with the permissions.  My document folder now has other as no access.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18783470
Nevermind, I'm back in
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18783472
Line 75 is: . move_uploaded_file($_FILES['strImage']['tmp_name'], $target_path)
0
 
LVL 14

Assisted Solution

by:Vel Eous
Vel Eous earned 1200 total points
ID: 18783497
Dont put your PHP move_uploaded_file function in your SQL statement.

Do your PHP upload_file functions first, then deal with the SQL, dont do to many things at once.

Personaly I dont think you should be concatinating your information into your DB anyway but perhaps that is just me.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18783506
Is this what you mean?

$target_path = "/Library/WebServer/Documents/images/";
$target_path = $target_path . basename( $_FILES['strImage']['name']);
$_FILES['strImage']['tmp_name'];
move_uploaded_file($_FILES['strImage']['tmp_name'], $target_path);

addslashes($strOtherservices);
addslashes($strServicesoffered);
addslashes($strProvidertagline);

$SQL = mysql_query("SELECT * FROM tblAdspace where strCompanyname = '" .$strCompanyname. "'")
or die(mysql_error());

if ($row = mysql_fetch_array($SQL)) {

$SQL = mysql_query("UPDATE tblAdspace SET "
       . "strProviderservice = '" . $strProviderservice . "', "
     . "strCompanyname='" . $strCompanyname . "', "
     . "strOwner='" . $strOwner . "', "
       . "strAddress='" . $strAddress . "', "
     . "strTown='" . $strTown . "', "
       . "strZipcode='" . $strZipcode . "', "
       . "strPhone='" . $strPhone . "', "
     . "str2ndphone='" . $str2ndphone . "', "
     . "strMobile='" . $strMobile . "', "
     . "strPager='" . $strPager . "', "
     . "strFax='" . $strFax . "', "
     . "strEmail='" . $strEmail . "', "
     . "strWebsite='" . $strWebsite . "', "
     . "strLicense='" . $strLicense . "', "
     . "strInsured='" . $strInsured . "', "
     . "strBonded='" . $strBonded . "', "
     . "strHours='" . $strHours . "', "
     . "str24houremerg='" . $str24houremerg . "', "
     . "strOtherservices='" . $strOtherservices . "', "
     . "strServicearea='" . $strServicearea . "', "
     . "strInbusiness_since='" . $strInbusiness_since . "', "
     . "strServicesoffered='" . $strServicesoffered . "', "
       . "strFreeestimate='" . $strFreeestimate . "', "
     . "strWorkguaranteed='" . $strWorkguaranteed . "', "
       . "strProvidertagline='" . $strProvidertagline . "', "
     . "strAd_size='" . $strAd_size . "', "
       . "strImage='" . $strImage . "'"
     . " WHERE strCompanyname = '" . $strCompanyname . "'");
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18783516
Ok, I got it to work finally!  Now my only problem is shortening the link.
0
 
LVL 14

Expert Comment

by:Vel Eous
ID: 18783541
$filename = basename( $_FILES['uploadedfile']['name']);
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18783559
Not sure what that was supposed to do?
0
 
LVL 14

Assisted Solution

by:Vel Eous
Vel Eous earned 1200 total points
ID: 18783581
That gets just the filename rather than the absolute file URL.

So,

$target_path = "/Library/WebServer/Documents/images/";
$target_path = $target_path . basename( $_FILES['strImage']['name']);
$filename = basename($_FILES['strImage']['name']);
$_FILES['strImage']['$filename'];
move_uploaded_file($_FILES['strImage']['$filename'], $target_path);
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18783813
That didn't seem to work.  I'm still getting the entire link.  I would like to have inserted only this:

/images/image
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18785238
I got it to work.  Thanks!
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question