Jump to content

Recommended Posts

Ive done some searching, and some previous topics touched on something similar to this, but I could not find an answer.

 

I have a script where you can login to an admin area, insert information into a textbox and the info will be recorded to an SQL database. Then, from the user side, the data is pulled from the database and displayed.

 

For example, on the user side of the site, I have the following line of code:

<?php echo $cgi->htmlEncode ( $arow [ "adminname" ] ); ?>

 

This obviously pulls the record in the database of the "adminname" and displays it on the page.

 

**************

 

What Im looking to do is have an image upload on the admin page which will be uploaded to the site, recorded in the database and displayed on the user side.

 

I cant seem to figure this out and I know that it is pretty simple because it is done all the time. Any help on this would be greatly appreciated.

 

Link to comment
https://forums.phpfreaks.com/topic/51351-upload-img-to-sql-then-display/
Share on other sites

You have to create an input-field like this:

<input type="file" name="foobar" />

 

To recieve the file, use the $_FILES - Array:

 

$fp = fopen($_FILES['tmp_name']);
$content = fread($fp, $_FILES['size']);
fclose($fp);

 

Of cause you should check first, if the file uploaded properly... simply check, if it exists..

 

But I would advise you not to stor it in the database, beacause there could be large amounts of data... that will maybe slow down your script..

Better store them in the filesystem with reference to the database.

The way that I do mine --  I have a table in my database called config -- inside it it has a "images_dir" in there with the path to images from the root directory...

 

Then in the admin panel there is a way for people to upload images, it uploads them, but then takes the name of the image and inserts that into a database table as well..

 

Then for viewing, i simply put the images_dir and the name in the database together...  makes for easy modification if you ever needed to do anything.

Thanks for the help. Ill see if I can get this to work based on your instructions.... Would anybody be willing to do this for me for a few bucks? To get a better idea of the project, go to www.agentzap.com/agentdemo.

 

All of the info you see on the page, realtor name, company, about me, etc. is all entered in a textbox in the admin area, then displayed on the frontside. I just need to do the same with an image, and I need to resize any uploaded images to a max width/height.

 

My email is jrobinson@sitefever.com

 

Thanks!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.