473,796 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php image upload script seems isn't working and i don't know why

tolkienarda
316 Contributor
hi all

I am using a php script to try to upload images to my database. i know i am connecting to my database because the image title is being wirtten to the database. but the image isn't example:

if i upload the coke emblem from my desktop and type in 'coke'; when i look into the phpmyadmin i see that the text coke was written to the database but in the pix field it said [BLOB - 0 Bytes] below is the code if anyone has insight i would be grateful

this script is live at http://www.steppinupwe bdesign.com/cms/imgupload.php
[PHP]
if ($_REQUEST[completed] == 1) {
// Need to add - check for large upload. Otherwise the code
// will just duplicate old file ;-)
// ALSO - note that latest.img must be public write and in a
// live appliaction should be in another (safe!) directory.
move_uploaded_f ile($_FILES['imagefile']['tmp_name'],"latest.img ");
$instr = fopen("latest.i mg","rb");
$image = addslashes(frea d($instr,filesi ze("latest.img" )));
if (strlen($instr) < 149000) {
mysql_query ("insert into pix (title, imgdata) values (\"".
$_REQUEST[whatsit].
"\", \"".
$image.
"\")");
} else {
$errmsg = "Too large!";
}
}

// Find out about latest image

$gotten = @mysql_query("s elect * from pix order by pid desc limit 1");
if ($row = @mysql_fetch_as soc($gotten)) {
$title = htmlspecialchar s($row[title]);
$bytes = $row[imgdata];
} else {
$errmsg = "There is no image in the database yet";
$title = "no database image available";
// Put up a picture of our training centre
$instr = fopen("../wellimg/ctco.jpg","rb") ;
$bytes = fread($instr,fi lesize("../wellimg/ctco.jpg"));
}

// If this is the image request, send out the image

if ($_REQUEST[gim] == 1) {
header("Content-type: image/jpeg");
print $bytes;
exit ();
}
?>

<html><head>
<title>Upload image</title>
<body bgcolor=white>< h2>latest picture</h2>
<font color=red><?= $errmsg ?></font>
<center><img src=?gim=1 width=144><br>
<b><?= $title ?></center>
<form enctype=multipa rt/form-data method=post>
<input type=hidden name=MAX_FILE_S IZE value=150000>
<input type=hidden name=completed value=1>
browse: <input type=file name=imagefile> <br>
comments: <input name=whatsit><b r>
then: <input type=submit></form><br>


</body>
</html>
[/PHP]

thanks eric
Feb 14 '07 #1
7 2556
xwero
99 New Member
why do you move the file if you store it in the database?

[PHP]
$image = addslashes(frea d(fopen ($_FILES['imagefile']['tmp_name'],'r'),filesize( $_FILES['imagefile']['tmp_name'])));
[/PHP]
Feb 14 '07 #2
tolkienarda
316 Contributor
i am not sure this script is one i downloaded the script and read all of the documentation but i still can't make it work

eric
Feb 15 '07 #3
xwero
99 New Member
you can try my code snippet to see if you get the image into the database.
Feb 15 '07 #4
tolkienarda
316 Contributor
and here is a stupid question for you

where do i put your snippit of code

sorry for the stupidity

eric
Feb 15 '07 #5
xwero
99 New Member
change this

[PHP]
$instr = fopen("latest.i mg","rb");

$image = addslashes(frea d($instr,filesi ze("latest.img" )));
[/PHP]

to this

[PHP]
$image = addslashes(frea d(fopen ($_FILES['imagefile']['tmp_name'],'r'),filesize( $_FILES['imagefile']['tmp_name'])));
[/PHP]

which version of php are you using? the rb parameter in fopen is only for php 5
Feb 15 '07 #6
tolkienarda
316 Contributor
your'e awesome thanks alot it works

eric
Feb 15 '07 #7
Rockdrala
1 New Member
Just a couple questions on this script. it looks like your code snippet is pointing to a temp directory to store the image. are you actually storing the physical image in the db? and wouldnt that be kinda hoggish on the db? :p

im not really seeing any authorization on the db either or what db to throw it in. i guess this script is assuming you have a already completed a login process that has got ya a cookie.
Jun 30 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

15
12019
by: lawrence | last post by:
I've been using the following function (yes, it is inelegant, what can I say, I wrote it a long time ago) to upload images. Haven't had a problem with it for at least a year, and I don't recall changing it anytime recently. Nevertheless, the script is suddenly dying on this line: if (copy($uploadedFile, $pathToImageFolder)){ This is the error I get:
1
3027
by: PeterB | last post by:
Hi! I'm using Pure ASP File Upload (http://www.asp101.com/articles/jacob/scriptupload.asp) to upload a file from a client to a server. I am testing both on a local IIS and a remote server. The welcome page has a browse button (for locating your local file), a textfield where the path is displayed, and a upload button. When clicking upload a VB ASP script is run, and the outcome is displayed on a new page. 1. On my local machine I got the...
0
1804
by: doffer | last post by:
I want to make a portfoliosystem where user can register and get their own portfolio... I've started the developer work, but I'm stuck on the image upload part... I'm experiencing some problems getting the picture resized and thumbnailed... I'm on a apache server running php 5 with 8MB php_memory. When uploading, the script works fine most times when uploading small files (below 100kb and sometimes up close to 300kb too), but when...
1
2511
by: John Thompson | last post by:
We're sooo close. When we load the page to upload the image, all of the prms go through except the binary image data. Using SQL server with the data type set to "image". Please help! Thanks- John
35
2676
by: Stan Sainte-Rose | last post by:
Hi, What is the better way to save image into a database ? Just save the path into a field or save the image itself ? I have 20 000 images (~ 10/12 Ko per image ) to save. Stan
15
5367
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run from the upload function: A generic error occurred in GDI+. Not sure what exactly that means. From what...
0
1915
by: Mattia | last post by:
************************************************** Manage image without exhausted memory ************************************************** Hi; I have a big problem. I must create a script that upload an image an then resize it, if width or height are more than 250px. Now, after upload an image (in this example I suppose that it's a JPEG image):
3
4435
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine when iam using a normal web page... but can't in content page.... Code in Master Page <%@ Master Language="C#" AutoEventWireup="true" CodeFile="submaster.master.cs" Inherits="submaster" %> <%@ Register Assembly="AjaxControlToolkit"...
1
4885
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop program,which can upload many file in folder.problem is,am unable to save my file name in to database.because i used same name for all input file type as file. i dont know get name of file.below i presented my coding for ur view.fed up with my coding..pls...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9524
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10449
Oralloy
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...
0
10217
jinu1996
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...
0
9047
agi2029
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...
1
7546
isladogs
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...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.