Current location: Hot Scripts Forums » Programming Languages » PHP » Picture upload to database?


Picture upload to database?

Reply
  #1 (permalink)  
Old 09-29-03, 12:38 PM
dayzeday dayzeday is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Joplin, MO
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Picture upload to database?

I am getting alot further with learning PHP & mySQL, however I am now to point where I am stuck again. I have set 3 fields in the database for pictures I need some direction on how to upload them from a php page and to display them in another page.

I tried displaying a file that was already uploaded and directing it to where the file was and obviously that did not work. SO... therefor I am stuck again.

Help please! I have to learn all of this in less than a week. I am getting there but I get stuck on little things like this.
Reply With Quote
  #2 (permalink)  
Old 09-30-03, 03:32 AM
marakkesh marakkesh is offline
Newbie Coder
 
Join Date: Sep 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
updloading to database

Hey dayze -

actually, there are a few issues involved here, and the easiest solution would be to check out a place like hotscripts.com and download a script that deals with file manipulation -

essentially what you are going to do is create some tables in mysql to hold about the image like the name, size, image type, etc. You don't actually store the image in the database (though I think it can be done, it's not really worth it for what I imagine you are trying to do.)

The steps you need to complete are:

1. Create you database

2. Create a form on your php page to upload images - making sure things like enctype are set correctly

3. Create a process page that does the following:

1. Copies the file from your local computer to your server (have to have correct file permissions on the remote folder you are copying to)
2. Inserts information about the file in the database (at the very least the image name)
3. notifies you whether the upload was successful

4. Create a view page where you can view all of the files that have been uploaded with options for linking to them and downloading.

You weren't very specific about what you wanted to do, and I know this sounds very general, which is why I would suggest you get a script that does what you want and modify it, especially if you are under time constraints.

Gordon
Reply With Quote
  #3 (permalink)  
Old 09-30-03, 12:38 PM
Niklas Niklas is offline
Newbie Coder
 
Join Date: Sep 2003
Location: www.swefi.com
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Reply With Quote
  #4 (permalink)  
Old 10-02-03, 11:11 AM
dayzeday dayzeday is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Joplin, MO
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Getting Error Messages

I have try all the codes that and I am getting error message that I am not sure what to do about:

Warning: unlink(/var/tmp/phpjPijsc): No such file or directory in /home/mtjmanag/public_html/PHP/upload.php on line 40 ( DIRECTORY IS THERE)

Warning: move_uploaded_file(/var/tmp/phpjPijsc): failed to open stream: No such file or directory in /home/mtjmanag/public_html/PHP/upload.php on line 45 ( DIRECTORY IS THERE)

Warning: move_uploaded_file(): Unable to move '/var/tmp/phpjPijsc' to 'x:/upload/350o0u.jpg' in /home/mtjmanag/public_html/PHP/upload.php on line 45 ( DIRECTORY IS THERE)

I am not sure how to correct this. HELP!
Reply With Quote
  #5 (permalink)  
Old 10-02-03, 12:17 PM
Niklas Niklas is offline
Newbie Coder
 
Join Date: Sep 2003
Location: www.swefi.com
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
are you sure you have chmoded the folders correctly?
Reply With Quote
  #6 (permalink)  
Old 10-02-03, 12:31 PM
dayzeday dayzeday is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Joplin, MO
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Niklas
are you sure you have chmoded the folders correctly?
it is set at 755
Reply With Quote
  #7 (permalink)  
Old 10-02-03, 01:13 PM
Niklas Niklas is offline
Newbie Coder
 
Join Date: Sep 2003
Location: www.swefi.com
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
umm i dont remember what 755 stands for, but you could try chmoding it to 777 and see if it works
Reply With Quote
  #8 (permalink)  
Old 10-02-03, 01:20 PM
dayzeday dayzeday is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Joplin, MO
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Niklas
umm i dont remember what 755 stands for, but you could try chmoding it to 777 and see if it works
Nope! 777 gives me the same warning message:

Here is the code that I am using;

<? // upload.php
// Constants. These are the values that determine if the file is accepted or not.
$dir = "x:/upload/"; // Directory where you want to put the files.
$maxfilesize = 1048576; // File size, in bytes. I've chosen 1MB here, which is 1048576 bytes. This is the usual cap for images.
$maxwidth = 100; // Max width in pixels.
$maxheight = 200; // Max height in pixels. I chose to use a standard screen res that produces about a 1MB image in Photoshop with a 72 dpi. Change as you see fit.

// File information. We'll be checking these values against our constraints above.
$filename = $_FILES['imagefile']['tmp_name']; // File being uploaded.
$filesize = filesize($filename); // File size of the file being uploaded.
$size = getimagesize($filename); // We're going to be using this for a dimensions check.
$width = $size[0]; // Width of the file being uploaded.
$height = $size[1]; // Height of the file being uploaded.

// Error checking and handling. Now we're going to either break out of the script, or we're going to continue onto the final upload.

if($filesize > $maxfilesize)
{
print("Max filesize of $maxfilesize breeched. File will not be accepted.");
unlink($filename); // This will remove the temporary file so we don't have to deal with it anymore.
}
if($width > $maxwidth)
{
print("Max width of $maxwidth breeched. File will not be accepted.");
unlink($filename); // This will remove the temporary file so we don't have to deal with it anymore.
}
if($height > $maxheight)
{
print("Max height of $maxheight breeched. File will not be accepted.");
unlink($filename); // This will remove the temporary file so we don't have to deal with it anymore.
}

// File copy and successful output. The file passed the 3 error check tests, and can not be copied to its final destination.

move_uploaded_file($_FILES['imagefile']['tmp_name'], $dir . $_FILES['imagefile']['name']); // Note that $dir is the directory you wish to upload the final file to. Modify as needed in the constants above.
$filename = $_FILES['imagefile']['name']; // Refresh the filename variable with the final filename, just to keep the variable clean and information up-to-date.
print("File upload complete.<br>Name: $filename<br>File Size: $filesize<br>Width: $width<br>Height: $height");
?>
Reply With Quote
  #9 (permalink)  
Old 10-08-03, 02:37 AM
tega tega is offline
New Member
 
Join Date: Sep 2003
Location: Austin
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Reply With Quote
  #10 (permalink)  
Old 10-09-03, 01:14 AM
marakkesh marakkesh is offline
Newbie Coder
 
Join Date: Sep 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
some code

Dayze -

What is the actual directory you are using? Is this on a local machine or on a webserver?

You should be using something like:

home/users/g/smith341/public_html/images

All of the stuff up until the /public should be provided to you by your host - after that, it's up to you... Just make sure the final directory (where you are putting the files) is chmod to 777..

Also, maybe something a little more straightforward would help. Here is some code I use:

PHP Code:



$absolute_path 
"/usr341/home/u/r/sitename/public_html/images/"

if (
$file != '') {
    if (
file_exists("$absolute_path/$filename")) {
        die(
"$filename already exists");
    }
    
    @
copy($file"$absolute_path/$filename");
    
    
$pic_info getimagesize($file);

    
$sql="Here I enter some info about the file into my database...";

That's it -

Gordon
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Share database over the Internet nitinkedia The Lounge 2 11-20-03 02:07 PM
SQL database registration form help vinhkhuong PHP 3 10-10-03 03:49 AM
Share database over the internet nitinkedia PHP 0 07-11-03 12:22 AM
Share database over the Internet nitinkedia New Members & Introductions 1 07-10-03 02:50 PM
Looking for a script to upload images in a database. boskyvora PHP 2 06-16-03 04:18 AM


All times are GMT -5. The time now is 06:23 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.