473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

User uploading pictures

Hi All,

I have a web site I am developing, and have a question. I would like
members to be able to upload pictures.

Do you think they should be saved as individual files or should they be
put in an MySQL database? Which would you recommend, and do you have any
sample code for accomplishing this?

Ciao . . . C.Joseph

And on the seventh day God said,
"I will rest . . . Murphy take over."
May 5 '06 #1
2 1691
Here ya go. This is the script that I made for one of my sites. The
form takes the userid, and if the image gets uploaded ok it gets
renamed to useridu.jpg (100u.jpg) I only allow jpg's for this script.
It then gets inserted in an images table as unapproved (0). After I
approve the images the image gets renamed to userid.jpg (100.jpg) and
the users profile gets updated with the new picture.
Upload form

<?php

echo "Upload an image<br><br>";
echo "
<form action=\"uploader.php\" method=\"post\"
enctype=\"multipart/form-data\">

<input type=\"file\" name=\"file\" size=\"50\">
<br/>
<input type=\"submit\" value=\"Upload File\">
<input type='hidden' name='userid' value='$userid'>
</form>[ <a href=users.php class=\"menulink\">Back</a> ]<br><br>";

?>

uploader.php

<?php
global $userid;
if($file_name !="")
{
$image_type = strstr($file_name, '.');

if($image_type == ".jpg"){
$file_name = $userid."u.jpg";
copy ("$file", "/www/htdocs/user_images/$file_name") or die("Could
not copy file");

include "connect.php";
$result = mysql_query("INSERT INTO images (userid,name) VALUES
('$userid','$file_name')") or die ("Error in insert sql:".
mysql_error());
include "disconnect.php";

include("mem_header.php");
echo "Your file has been uploaded!<br><br>";
echo "<br>Your photo is pending approval<br><br>";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"2; URL=users.php\">";
include("mem_footer.php");
}else{
include("mem_header.php");
echo "Incorrect File Type. Your file must be a JPG<br><br>";
echo "Your file has NOT been uploaded!<br><br>";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"2;
URL=users.php?cmg=Upload\">";
include("mem_footer.php");
}

}
else {
include("mem_header.php");
echo "No file specified<br><br>";
echo "Your file has NOT been uploaded!<br><br>";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"2;
URL=users.php?cmg=Upload\">";
include("mem_footer.php");
}
?>

May 5 '06 #2
Chris - SyracuseCS.com wrote:
Here ya go. This is the script that I made for one of my sites. The
form takes the userid, and if the image gets uploaded ok it gets
renamed to useridu.jpg (100u.jpg) I only allow jpg's for this script.
It then gets inserted in an images table as unapproved (0). After I
approve the images the image gets renamed to userid.jpg (100.jpg) and
the users profile gets updated with the new picture.
Upload form

<?php

echo "Upload an image<br><br>";
echo "
<form action=\"uploader.php\" method=\"post\"
enctype=\"multipart/form-data\">

<input type=\"file\" name=\"file\" size=\"50\">
<br/>
<input type=\"submit\" value=\"Upload File\">
<input type='hidden' name='userid' value='$userid'>
</form>[ <a href=users.php class=\"menulink\">Back</a> ]<br><br>";

?>

uploader.php

<?php
global $userid;
if($file_name !="")
{
$image_type = strstr($file_name, '.');

if($image_type == ".jpg"){
$file_name = $userid."u.jpg";
copy ("$file", "/www/htdocs/user_images/$file_name") or die("Could
not copy file");

include "connect.php";
$result = mysql_query("INSERT INTO images (userid,name) VALUES
('$userid','$file_name')") or die ("Error in insert sql:".
mysql_error());
include "disconnect.php";

include("mem_header.php");
echo "Your file has been uploaded!<br><br>";
echo "<br>Your photo is pending approval<br><br>";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"2; URL=users.php\">";
include("mem_footer.php");
}else{
include("mem_header.php");
echo "Incorrect File Type. Your file must be a JPG<br><br>";
echo "Your file has NOT been uploaded!<br><br>";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"2;
URL=users.php?cmg=Upload\">";
include("mem_footer.php");
}

}
else {
include("mem_header.php");
echo "No file specified<br><br>";
echo "Your file has NOT been uploaded!<br><br>";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"2;
URL=users.php?cmg=Upload\">";
include("mem_footer.php");
}
?>

Hi Chris,

Then I am assuming that you are recommending that I save individual
files.

I will try your script this afternoon and let you know how it works out.

Thank you so much for the recommendation.

Ciao . . . C.Joseph

And on the seventh day God said,
"I will rest . . . Murphy take over."
May 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sirano | last post by:
Hello, I'll want automatic upload pictures from a specified folder to the internet with PHP code. Or does somebody know a Website where I could find an answer for this. Thanks, Sirano
5
by: xool | last post by:
Hi all Can anyone tell me the simplest easiest way to upload pictures to a directory. It's for a content management page - text boxes for new record information and a file browse form box for...
3
by: Jason Chu | last post by:
I've written a file uploading part of my application using the IHttpModule. So now, I don't have the memory problem of uploading something big. Problem: I can't find which function I have to...
9
by: C.Joseph Drayton | last post by:
Hi All, I have a web site I am developing, and have a question. I would like members to be able to upload pictures. Do you think they should be saved as individual files or should they be put...
1
slapshock
by: slapshock | last post by:
hi!!!!!! is someone up there can give me the codes of uploading and retrieving pictures in visual basic 6.0........... i really need those codes..........thnx
0
by: lyealain | last post by:
hi guys.. i have spent up my time looking and understanding the sample code from everywhere for uploading picture into mysql database by using asp script.. but i found it very hard to understand......
1
by: onye52000 | last post by:
Hi. I want to be able to change the text and pictures of a flash movie from a control panel on the same running flash movie. I will need to upload pictures on the movie with the necessary text...
1
by: recordlovelife | last post by:
Hi all. I need to make a file uploader, so a client can upload pictures to a directory on their shared server, so that they can later include the photos in news updates. I simply want to take...
2
by: shreedhan | last post by:
Hi, I have a page for uploading pictures I have limited the file uploaded to be jpg ( and other picture types) and size upto 2 MB. Everything goes well, except when I give files larger than 8...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.