Ok, I had a more barebones version of this script working, but when I
tried to put it in with my larger script, it broke. I think the problem
lies somewhere in the uploading, but I'm not sure of this. Anyway,
here's what I have:
index.php
---------------------------------
<?
include("header .inc");
if (!isset($_SESSI ON['username']) or ($_SESSION['username'] == "Guest")) {
header ("Location: http://www.thisisfake. com/index.php");
}
dbconnect();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Upload </title>
</head>
<body>
<center>
<?
if($id) {
switch ($action) {
case "delete":
$data = mysql_query("SE LECT id,uploader FROM files WHERE id = '$id'");
$id = mysql_result($d ata,0,"id");
$uploader = mysql_result($d ata,0,"uploader ");
if ($_SESSION["username"] == $uploader || $_SESSION["level"] ==
"admin") {
mysql_query("DE LETE FROM files WHERE id = '$id'");
echo "File deleted";
echo '<META HTTP-EQUIV="refresh"
content="2;URL= http://www.thisisfake. com/upload/">';
} else {echo "Invalid permissions";}
break;
default: //Echo contents if image, else send as file download
$query = "select mimetype, data from files where id = $id";
$result = mysql_query($qu ery);
$data = mysql_result($r esult,0,"data") ;
$type = mysql_result($r esult,0,"mimety pe");
if ($type == "image/pjeg" || $type == "image/jpeg" || $type ==
"image/x-png" || $type == "image/png" || $type == "image/gif"|| $type ==
"image/bmp") {
echo base64_decode($ data);
} else {
get($id); //This send the file as a download, instead of echoing the
contents
}
break;
}
} else {
// Listing of files and the form
echo"
<form method=POST action=upload.p hp enctype=multipa rt/form-data>
<p>File to upload:<br>
<input type=file name=file>
<input type='submit' name='submit' value='Upload'>
</form>
";
//All this stuff works
echo "<p></p>";
if ($data = getInfo()) {
echo '<table border="0" align="center">
<tr bgcolor="#bad1d 1">
<td>File Name</td>
<td><center>Fil e Size</center></td>
<td><center>Mim e Type</center></td>
<td><center>Che cksum</center></td>
<td><center>Ext ension</center></td>
<td><center>Upl oader</center></td>
<td><center>Dat e</center></td>
<td><center>Opt ion</center></td>
</tr>
';
for ($i=0; $i<count($data) ; $i++) {
echo '
<tr bgcolor=#CCCCCC >
<td><a
href="view.php? id='.$data[$i]["id"].'">'.$data[$i]["file_name"].'</a></td>
<td>'.$data[$i]["file_size"].'</td>
<td>'.$data[$i]["mimetype"].'</td>
<td>'.$data[$i]["checksum"].'</td>
<td>'.$data[$i]["extension"].'</td>
<td>'.$data[$i]["uploader"].'</td>
<td>'.$data[$i]["date"].'</td>';
if ($_SESSION["username"] == $data[$i]["uploader"] ||
$_SESSION["level"] == "admin") {
echo '<td><a
href="index.php ?action=delete& id='.$data[$i]["id"].'">Delete</a></td>';}
echo '</tr>
';
}
echo '</table>';
echo '<br>';
echo 'Number of files: ';
echo blobcount();
echo '<br>';
}
}
?>
</center>
</body>
</html>
upload.php
----------------------------------------------
<?
include('header .inc');
dbconnect();
$type = $file_type;
if ($type == "image/pjeg" || $type == "image/jpeg" || $type ==
"image/x-png" || $type == "image/png" || $type == "image/gif") {
$handle = fopen($file,'rb ');
$file_content = fread($handle,f ilesize($file)) ;
fclose($handle) ;
$encoded = chunk_split(bas e64_encode($fil e_content));
$uploader = $_SESSION['username'];
$sql = "INSERT INTO files (id, file_name, data, file_size, mimetype,
extension, checksum, uploader, date) VALUES ('', '".$file_name." ',
'".$encoded. "', '".filesize($fi le)."', '".$file_type." ',
'".getExtension ($blob_name)."' , '".generate_sfv _checksum($file )."',
'".$uploader."' , NOW())";
mysql_query($sq l);
} else {
$handle = fopen($file,'rb ');
$file_content = fread($handle,f ilesize($file)) ;
fclose($handle) ;
$encoded = chunk_split(bas e64_encode($fil e_content));
$uploader = $_SESSION['username'];
$sql = "INSERT INTO files (id, file_name, data, file_size, mimetype,
extension, checksum, uploader, date) VALUES ('', '".$file_name." ',
'".$encoded. "', '".filesize($fi le)."', '".$file_type." ',
'".getExtension ($blob_name)."' , '".generate_sfv _checksum($file )."',
'".$uploader."' , NOW())";
mysql_query($sq l);
}
//}
header ("Location: http://www.thisisfake. com/upload");
?>
view.php
---------------------------------------------------------
<?
echo '<img src="http://www.thisisfake. com/upload/index.php?id='. $id.'">';
?>
I may have broken it further after the initial breaking, so if something
seems doubly broken that might be it. If you need more information just ask. 2 1895
Plex <in*****@thisis fake.com> wrote in
news:-M************** ******@comcast. com: I may have broken it further after the initial breaking, so if something seems doubly broken that might be it. If you need more information just ask.
error messages, buddy, error messages. surely you're not expecting someone
to debug that line by line??
Ok, I fixed it myself, all it was was the index.php was outputting html
regardless of whether there was an image data request, so as a result
the data send included html in it, which made the image "corrupt". This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: yawnmoth |
last post by:
i have a script that accesses images on a fairly frequent basis,
however, i'm thinking that it would be better to have them in an sql
database, instead, for the same reason that it is generally preferable
to access data in an sql database over a text file. the images are
small (i don't think any exceed 350 bytes), so i don't expect it'll
put a lot of strain on the sql server.
anyway, i currently load the images using ImageCreateFromGIF,...
|
by: Srdjan Pejic |
last post by:
Hello,
I have a problem that I have not been able to solve, even after
searching the web. I have stored couple of images in the MySQL database
and I am trying to get them displayed on a web page with PHP.
Now, before we go any further, I want to make it clear that I am very
aware of the current debate about storing images in the database. I
understand both sides, however this is something I want to do for fun,
as well as good learning.
|
by: bissatch |
last post by:
Hi,
I am currently writing a news admin system. I would like to add the
ability to add images to each article.
What I have always done in the past is uploaded (using a form) the
image to a folder on the server and then in the database table that I
INSERT the news article, I'll store the path of the uploaded image.
To me this seems a bad idea as if the image paths were changed on the
|
by: Alan |
last post by:
Hi,
I'm converting a database application from Access 97 to C#/SQL Server. Old
database contains some images in OLE fields. I've figured out that there's
OLE header preceeding actual image data and dealt with some of the images
which were in standard BMP format but most of the images are in some other
format which is displayed ok in access application and can be copy/pasted to
any image editor but when doubleclicking it doesn't open any...
|
by: Neo Geshel |
last post by:
I am seeking to hand-roll my own blog in ASP.NET 2.0 and SQLExpress
2005. Why? Because I can. Because I will gain experience.
The one thing that has me stumped at square one is inline images. That
is, images inline with the actual content of the blog itself. Is there
an example that I can be pointed to, where I can examine some code and
figure out how to do this? Frankly I haven't got a clue, aside from
breaking the content up into...
| |
by: Wayne Smith |
last post by:
I've come up against a major headache that I can't seem to find a solution
for but I'm sure there must be a workaround and I would really be grateful
of any help.
I'm currently building a web site for a small club I belong to and one of
the features I would like to include is the ability to allow users to upload
image files.
unfortunately the servers web root www folder only allows READ and EXECUTE
permissions, which makes it...
|
by: eholz1 |
last post by:
Hello Members,
I am setting up a photo website. I have decided to use PHP and MySQL.
I can load jpeg files into the table (medium blob, or even longtext)
and get the image(s) to display without a problem. I am using
chunk_split(data) and the base64_encode and base64_decode on the files.
I do a select from the database, and then echo the image (with
header(Content Type: image/jpeg)
and the decoded image displays fine. Yes, I have...
|
by: najimou |
last post by:
Hi everyone
I will be having a split database, running on 2 computers via mapped
drive.
computer "A" will have one front end and the back end located in c:
\mydatabse
2 tables have links to many images stored as c:\mydatabse\images
\images.jpg
so computer A has no problem accessing the picture
|
by: ttamilvanan81 |
last post by:
Hai everyone,
I need to provide the slideshow for the images.
I have upload the images into database. Then i will retrive all the images from the database and provide the slideshow for those images. I have try with the following jsp code.
<%@ page language="java" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.sql.Connection.*"%>
<%@ page import="java.awt.image.*"%>
|
by: Keith Hughitt |
last post by:
Hi all,
I am having trouble preloading images in a javascript application, and
was wondering if anyone had any suggestions.
Basically I have a bunch of images stored in a database as BLOBs. At
any given point in time a subset of those images is displayed on-
screen. At certains times I want to swap out those on screen with new
ones from the database, and do some as seamlessly as possible.
So what I've tried to do is first create Image...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |