Jump to content

File Uploader- Getting the location of the just uploaded file


HoTDaWg

Recommended Posts

Hello,

I am creating a photo gallery for the awsome people on my site (if any lol). What I am doing is once the image is uploaded, I want all the info added to a database. Everything is working great. The only problem is that I can not seem to get the location of the file once it is uploaded right. Take a look at the dumping data of my mySql database once I export it:

[code]
-- phpMyAdmin SQL Dump
-- version 2.6.4-pl2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Mar 13, 2006 at 05:22 PM
-- Server version: 4.1.14
-- PHP Version: 4.3.11
--
-- Database: `cortez_photoalbums`
--

-- --------------------------------------------------------

--
-- Table structure for table `images`
--

CREATE TABLE `images` (
  `id` int(15) NOT NULL auto_increment,
  `imageurl` blob NOT NULL,
  `titled` varchar(255) NOT NULL default '',
  `contributedby` varchar(22) NOT NULL default '',
  `date` varchar(50) NOT NULL default '0000-00-00',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6;

--
-- Dumping data for table `images`
--

INSERT INTO `images` VALUES (1, 0x2275706c6f6164732f22202e20245f46494c45535b2266696c65225d5b226e616d65225d, '4', 'some_guy', '03.13.06');
INSERT INTO `images` VALUES (2, 0x2275706c6f6164732f225b2266696c65225d5b226e616d65225d, '1', 'some_guy', '03.13.06');
INSERT INTO `images` VALUES (3, 0x2275706c6f6164732f225b2266696c65225d5b226e616d65225d, '7', 'some_guy', '03.13.06');
INSERT INTO `images` VALUES (4, 0x2275706c6f6164732f225b226e616d65225d, '6', 'some_guy', '03.13.06');
INSERT INTO `images` VALUES (5, 0x282275706c6f6164732f22202e20245f46494c45535b2266696c65225d5b226e616d65225d29, '5', 'asd', '03.13.06');
[/code]

weird eh? Here is the code for upload.html:

[code]
<html>
<head>
<title>Upload now!</title>
</head>

<form action="upload.php" method="post" enctype="multipart/form-data">
  <p>File Upload</p>
  <label for="file">File</label>
  <input type="file" name="file" id="file" /><br><br>
  <label for="titled">File Name</label><input type="text" name="titled"><br><br>
  <label for="contributedby">Contributed by:</label><input type="text" name="contributedby"<br><br>
  <br />
  <input type="submit" name="submit" value="Submit" />
</form>
<body bgcolor="#FFFFFF">

</body>


</html>
[/code]

here is the code for upload.php:

[code]
<?php
if (($_FILES["file"]["type"] == "image/gif" OR "images/jpg") &&
($_FILES["file"]["size"] < 1500000)) {
  echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  echo "Uploading " . $_FILES["file"]["name"];
  echo " (" . $_FILES["file"]["type"] . ", ";
  echo ceil($_FILES["file"]["size"] / 1024) . " Kb).<br />";

  if (file_exists("uploads/" . $_FILES["file"]["name"])) {
    echo $_FILES["file"]["name"] . " already exists.  ";
    echo "Please delete the destination file and try again.";
  } else {
    move_uploaded_file($_FILES["file"]["tmp_name"],
    "uploads/" . $_FILES["file"]["name"]);

    echo "The file has been successfully uploaded!:D";

$imageurl = '("uploads/" . $_FILES["file"]["name"])';

$titled = $_REQUEST['titled'];
$contributedby = $_REQUEST['contributedby'];
$date = date("m.d.y");

$titled=strip_tags($titled);
$contributedby=strip_tags($contributedby);

$titled=addslashes($titled);
$contributedby=addslashes($contributedby);

$conn = mysql_connect("localhost","cortez","165745");

//now choose the database to use
mysql_select_db("cortez_photoalbums");

//Save the request in SQL syntax to a string
$request = "INSERT INTO images values(0,'".$imageurl."','".$titled."','".$contributedby."','".$date."')";

$results = mysql_query($request,$conn);

  }

} else
  echo "Sorry, we only accept .GIF, and .jpg images under 1500 Kb for upload.";
?>
[/code]

I would love any assistance in solving this problem.

HoTDaWg
Link to comment
Share on other sites

appreciate the help a lot, but according to my export code, my code still doesnt work:

[code]
-- phpMyAdmin SQL Dump
-- version 2.6.4-pl2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Mar 13, 2006 at 05:58 PM
-- Server version: 4.1.14
-- PHP Version: 4.3.11
--
-- Database: `cortez_photoalbums`
--

-- --------------------------------------------------------

--
-- Table structure for table `images`
--

CREATE TABLE `images` (
  `id` int(15) NOT NULL auto_increment,
  `imageurl` blob NOT NULL,
  `titled` varchar(255) NOT NULL default '',
  `contributedby` varchar(22) NOT NULL default '',
  `date` varchar(50) NOT NULL default '0000-00-00',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7;

--
-- Dumping data for table `images`
--

INSERT INTO `images` VALUES (1, 0x2275706c6f6164732f22202e20245f46494c45535b2266696c65225d5b226e616d65225d, '4', 'some_guy', '03.13.06');
INSERT INTO `images` VALUES (2, 0x2275706c6f6164732f225b2266696c65225d5b226e616d65225d, '1', 'some_guy', '03.13.06');
INSERT INTO `images` VALUES (3, 0x2275706c6f6164732f225b2266696c65225d5b226e616d65225d, '7', 'some_guy', '03.13.06');
INSERT INTO `images` VALUES (4, 0x2275706c6f6164732f225b226e616d65225d, '6', 'some_guy', '03.13.06');
INSERT INTO `images` VALUES (5, 0x282275706c6f6164732f22202e20245f46494c45535b2266696c65225d5b226e616d65225d29, '5', 'asd', '03.13.06');
INSERT INTO `images` VALUES (6, 0x75706c6f6164732f342e676966, '4', 'some_guy', '03.13.06');

[/code]

thanks a lot though
Link to comment
Share on other sites

thank you all so much for your help. The script is working Great! The only problem is I get the following error when using my latest page [b]gallery.php[/b]:

[code]
Parse error: syntax error, unexpected T_STRING in /home/cortez/public_html/testscripts/photoalbums/gallery.php on line 24
[/code]

Here is the script:

[code]<html>
<head>
<title>Homework Administration- Delete Homework</title>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
</head>
<body>
<?php

$conn = mysql_connect("localhost","cortez","165745");

//now choose the database to use
mysql_select_db("cortez_photoalbums");

$id = $_GET['id']; // retrieve id passed via URL
if (isset($id)) {
    $query = "DELETE FROM images WHERE id = '$id' ";
    $result = mysql_query($query);
}
$getimages = mysql_query("SELECT * FROM images ORDER BY id DESC");
while($r=mysql_fetch_array($getimages)) {
    extract($r); //remove the $r so its just $variable
    echo("<hr>
    Id: $id <br>
    Image: <image src="images/$imageurl" height="50" width="50"><br>
    Date: $date<br>
    <a href='". $_SERVER['PHP_SELF']. "?id=". $id. "'>delete</a>");
}
?>

</body>
</html>
[/code]

I would be nowhere today if i had not found out about this site,

Hotdawg

PS: the reason I am adding the uploads/ in my image tag is because take a look at my database when I exported it:

[code]
-- phpMyAdmin SQL Dump
-- version 2.6.4-pl2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Mar 14, 2006 at 03:50 PM
-- Server version: 4.1.14
-- PHP Version: 4.3.11
--
-- Database: `cortez_photoalbums`
--

-- --------------------------------------------------------

--
-- Table structure for table `images`
--

CREATE TABLE `images` (
  `id` int(15) NOT NULL auto_increment,
  `imageurl` varchar(255) NOT NULL default '',
  `titled` varchar(255) NOT NULL default '',
  `contributedby` varchar(22) NOT NULL default '',
  `date` varchar(50) NOT NULL default '0000-00-00',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=9;

--
-- Dumping data for table `images`
--

INSERT INTO `images` VALUES (1, '"uploads/" . $_FILES["file"]["name"]', '4', 'some_guy', '03.13.06');
INSERT INTO `images` VALUES (2, '"uploads/"["file"]["name"]', '1', 'some_guy', '03.13.06');
INSERT INTO `images` VALUES (3, '"uploads/"["file"]["name"]', '7', 'some_guy', '03.13.06');
INSERT INTO `images` VALUES (4, '"uploads/"["name"]', '6', 'some_guy', '03.13.06');
INSERT INTO `images` VALUES (5, '("uploads/" . $_FILES["file"]["name"])', '5', 'asd', '03.13.06');
INSERT INTO `images` VALUES (6, 'uploads/4.gif', '4', 'some_guy', '03.13.06');
INSERT INTO `images` VALUES (7, '2.gif', '2', 'some_guy', '03.13.06');
INSERT INTO `images` VALUES (8, '29.gif', 'some image', 'some guy', '03.14.06');
[/code]
Link to comment
Share on other sites

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.