Hello:
Try these two solutions:
-Remove the session_start from the beginning, I think you are not
using sessions and this might cause output problems on some browsers
-Conmute the echo $data; and echo $resume; lines to show up the resume
first and tell me what happens
In any case, it would be nice if you post the code that is echoed to
the browser, you can get it this way:
-Access to the script using your browser
-Use the option of your browser to "view the source code"
-Copy the results and post them here
We will work on this answer until you get the desired results.
Regards. |
Request for Answer Clarification by
galgal1-ga
on
04 Aug 2003 08:35 PDT
Hello,
Thank you for the quick responce. I did what you said and the same
thing happend (it does not matter which one goes first). The picture
doesn't let any other text or button on the page. I don't know if this
will help but when I put the picture and resume in a table the picture
comes out in codes and that is the only time the resume shows up. Also
for some reason I can't get the source of the script because when I go
to my page it is unclickable. You can go and try to get the source
code from
www.htauditions.com/getdata.php?user=patarok
I am very sorry that I can't get the source code for you.
Here is the updated script:
<?
// getdata.php3 - by Florian Dittmer <dittmer@gmx.net>
// Example php script to demonstrate the direct passing of binary data
// to the user. More infos at http://www.phpbuilder.com
// Syntax: getdata.php3?id=<id>
// you may have to modify login information for your database
include ("connection2.php");
@mysql_select_db("patarok");
$query = "SELECT bin_data,resume FROM `Members` where
name='$user'";
$result = @MYSQL_QUERY($query);
$data = @MYSQL_RESULT($result,0,"bin_data");
echo $resume;
echo $data;
$resume = @MYSQL_RESULT($result,0,"resume");
echo "<p align='center'>";
?>
<form action="delete.php" mathod="post">
<input type="submit" name="Delete" value="Delete">
</form>
|
Clarification of Answer by
joseleon-ga
on
04 Aug 2003 10:01 PDT
Hello:
Thanks for the link, this way I have discovered what is your
problem. When the picture is uploaded, the entire image (in binary
form) is stored in the database so when you echo the image to the
browser, is echoed in binary form, instead of using HTML.
So the browser recognizes the data as an image and doesn't process the
rest of your output.
There are several solutions, but I think the most aproppiate would be
to split the getdata.php script in two parts, one to show the image
and another to show the resume and join everything using frames. Is
this solution suitable to you?
Regards.
|
Request for Answer Clarification by
galgal1-ga
on
04 Aug 2003 10:27 PDT
Hello Jose,
Thank you again for answering. The solution you gave me doesn't fit
what I need and I am sorry. Is there any way that they could all just
stay on one page since I want a delete button that is suppose to
delete the picture out of the Database. If there is any way they can
all (resume,delete button, and picture) be on one page that would be
great.
Thank you for your time.
|
Clarification of Answer by
joseleon-ga
on
04 Aug 2003 11:15 PDT
Hello:
There are two solutions for this:
-Change the upload script to save the image as a file in your server
and store the path on the database. Then echo the image as an IMG tag
pointing to the image.
-Modify the get script to save the binary image to a file each time
you need to show it up
The first solution is the *correct* one, while the second is the
fastest to implement.
You choose... I will implement any solution you want.
Regards.
|
Request for Answer Clarification by
galgal1-ga
on
04 Aug 2003 12:24 PDT
Hello,
Thank you for your time. We prefer the first option and I think this
is great for me. What information will you need in order to do this? I
will provide you with anything you need since I trust you.
Here is the upload script:
<? session_start(); ?>
<HTML>
<HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
<BODY>
<?php
if (isset($HTTP_POST_VARS['form_description'])) {
include ("connection2.php");
mysql_select_db("patarok");
$form_description = $HTTP_POST_VARS['form_description'];
$form_data_type = $_FILES['userfile']['type'];
$form_data_name = $_FILES['userfile']['name'];
$form_data_size = $_FILES['userfile']['size'];
$data = addslashes(fread(fopen($_FILES['userfile']['tmp_name'], "r"),
filesize($_FILES['userfile']['tmp_name'])));
$query = "Update Members Set
description='$form_description',bin_data='$data',filename='$form_data_name',filesize='$form_data_size',filetype='$form_data_type'
where name='$user'";
$result = mysql_query($query)
or die ("Couldn't execute query.");
echo "<h2>File Uploaded Successfully!</H2><br><br>
<p align=center><a href='uploadform2.php?user=$user'>Upload another
picture</A></P>
<p align=center><a href='resumeupdate.php?name='$user''>Write your
resume</a></p>
<p align=center><a href='account.php?name='$user''>Finish and go to
your account</a></P>";
MYSQL_CLOSE();
}
?>
</BODY>
</HTML>
And here is the form before it:
<? session_start(); ?>
<HTML>
<HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
<BODY>
<?
echo "<form action='uploadga.php?user=$user'
method='post' enctype='multipart/form-data' name='picup'
target='_self' id='picup'>";
?>
File Description:<br>
<input type="text" name="form_description" size="40" maxlength="100">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>File to upload/store in database:<br>
<input type="file" name="userfile" value="*.jpg" size=30>
<p><input type="submit" name="submit" value="submit">
</form>
</BODY>
</HTML>
Thank you VERY MUCH!
|
Clarification of Answer by
joseleon-ga
on
04 Aug 2003 23:55 PDT
Hello:
Upload script:
<? session_start(); ?>
<HTML>
<HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
<BODY>
<?php
if (isset($HTTP_POST_VARS['form_description']))
{
include ("connection2.php");
mysql_select_db("patarok");
$form_description = $HTTP_POST_VARS['form_description'];
$form_data_type = $_FILES['userfile']['type'];
$form_data_name = $_FILES['userfile']['name'];
$form_data_size = $_FILES['userfile']['size'];
$data = addslashes(fread(fopen($_FILES['userfile']['tmp_name'], "r"),
filesize($_FILES['userfile']['tmp_name'])));
$source_file = $_FILES['userfile']['tmp_name'];
$dest_file = '/home/www/imagesdir/'.$form_data_name;
copy($source_file, $dest_file);
$query = "Update Members Set description='$form_description',
filename='$form_data_name',filesize='$form_data_size',filetype='$form_data_type'
where name='$user'";
$result = mysql_query($query) or die ("Couldn't execute query.");
echo "<h2>File Uploaded Successfully!</H2><br><br> <p align=center><a
href='uploadform2.php?user=$user'>Upload another picture</A></P>";
echo "<p align=center><a href='resumeupdate.php?name='$user''>Write
your resume</a></p><p align=center><a
href='account.php?name='$user''>Finish and go to your
account</a></P>";
mysql_close();
}
?>
</BODY>
</HTML>
As you can see, stores the uploaded files to a directory on your
server:
$dest_file = '/home/www/imagesdir/'.$form_data_name;
Change this path according to your server, this directory must be
writeable by the webserver.
And the getdata script:
<? session_start();
// getdata.php3 - by Florian Dittmer <dittmer@gmx.net>
// Example php script to demonstrate the direct passing of binary data
// to the user. More infos at http://www.phpbuilder.com
// Syntax: getdata.php3?id=<id>
// you may have to modify login information for your database
include ("connection2.php");
@mysql_select_db("patarok");
$query = "SELECT filename,resume FROM `Members` where name='$user'";
$result = @MYSQL_QUERY($query);
$data = @MYSQL_RESULT($result,0,"filename");
echo "<IMG SRC=\"imagesdir/$data\">";
$resume = @MYSQL_RESULT($result,0,"resume");
echo "<p align='center'>";
echo $resume;
?>
<form action="delete.php" mathod="post">
<input type="submit" name="Delete" value="Delete">
</form>
This script echoes the image as an IMG tag pointing to your imagedir:
echo "<IMG SRC=\"imagesdir/$data\">";
I think we will need some clarifications more to config the scripts to
your server setup, don't hesitate to request for help.
Regards.
|
Request for Answer Clarification by
galgal1-ga
on
05 Aug 2003 09:27 PDT
Hello,
Thank you for your effort but I think my host(www.webmasters.com) does
not allow this script to upload files to one of their files. I think
so since I got this message after I tried the great script you gave
me:
Warning: SAFE MODE Restriction in effect. The script whose uid is
10527 is not allowed to access / owned by uid 0 in
/usr/local/4admin/apache/vhosts/htauditions.com/httpdocs/uploadtest.php
on line 9
I am very sorry about this and I will be very greatful if you have any
other idea on how to do what I am trying to do. Thank you for your
great script and have a great day.
|
Request for Answer Clarification by
galgal1-ga
on
05 Aug 2003 11:46 PDT
Hello again,
I think that you have done your job very well and it is not your fault
that the script does not work for us and it won't be fair to you if
you did all this work for $15 so when we are done with this I promise
I will give you a tip to pay you as nuch as I can for the great job
you have done.
Thank and I am waiting for a responce.
|
Clarification of Answer by
joseleon-ga
on
06 Aug 2003 06:27 PDT
Hello:
Don't throw the towel yet!!!
First, check out the path you are trying to copy the file, because
by the error message you post, it seems you are copying it to the
root(/) dir instead to a directory owned by you. You can check it by
placing
echo $dest_file;
just before the line
copy($source_file, $dest_file);
and post here the results, if you want, just tell me where are the
scripts online and I will do it for you.
I don't think SAFE MODE prevents you from access your own files, in
any case, if your host has configured PHP this way, maybe it's time to
change to another host ;-)
Regards.
|
Request for Answer Clarification by
galgal1-ga
on
06 Aug 2003 08:07 PDT
Hello again,
I forgot to give you the two scripts.
Here is uploadform.php wich is the form where they fill out the
address of the picture:
<? session_start(); ?>
<HTML>
<HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
<BODY>
<?
echo "<form action='uploadtest.php?user=$user'
method='post' enctype='multipart/form-data' name='picup'
target='_self' id='picup'>";
?>
File Description:<br>
<input type="text" name="form_description" size="40" maxlength="100">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>File to upload/store in database:<br>
<input type="file" name="userfile" value="*.jpg" size=30>
<p><input type="submit" name="submit" value="submit">
</form>
</BODY>
</HTML>
If you want to open it you can go to www.htauditions.com?user=patarok
Then here is uploadtest.php and it uploads the picture to the server:
<? session_start(); ?> <HTML> <HEAD><TITLE>Store binary data into SQL
Database</TITLE></HEAD> <BODY>
<?php if (isset($HTTP_POST_VARS['form_description'])) { include
("connection2.php");
mysql_select_db("patarok"); $form_description =
$HTTP_POST_VARS['form_description'];
$form_data_type = $_FILES['userfile']['type']; $form_data_name =
$_FILES['userfile']['name'];
$form_data_size = $_FILES['userfile']['size'];
$data = addslashes(fread(fopen($_FILES['userfile']['tmp_name'], "r"),
filesize($_FILES['userfile']['tmp_name'])));
$source_file = $_FILES['userfile']['tmp_name'];
$dest_file = '/httpdocs/photos'.$form_data_name;
copy($source_file, $dest_file);
$query = "Update Members Set description='$form_description',
filename='$form_data_name',filesize='$form_data_size',filetype='$form_data_type'
where name='$user'"; $result = mysql_query($query) or die ("Couldn't
execute query.");
echo "<h2>File Uploaded Successfully!</H2><br><br> <p align=center><a
href='uploadform2.php?user=$user'>Upload another picture</A></P>";
echo "<p align=center><a href='resumeupdate.php?name='$user''>Write
your resume</a></p><p align=center><a
href='account.php?name='$user''>Finish and go to your
account</a></P>";
mysql_close(); }
?>
</BODY> </HTML>
If you want to open it go to www.htadutions.com?user=patarok
Please edit these scripts so they would work with the server(which I
gave you the information on in the other clarification).
|
Clarification of Answer by
joseleon-ga
on
08 Aug 2003 01:52 PDT
Hello:
I have finally fixed all the problems in your server, I have updated
these files:
uploadtest.php
uploadform.php
connection2.php
getdata.php
The problem was in the path you were using on the upload script, you
were using the FTP path, while PHP requires the *real* path, that in
your server is:
/usr/local/4admin/apache/vhosts/htauditions.com/httpdocs/photos/
I have also fixed the problem you had on the connection2.php script,
you weren't connecting to the database, you were using the
mysql_connect function in uppercase.
And I have also fixed the getdata.php script to show the photo and
then the resume.
So first, go to the upload form:
Upload form
http://www.htauditions.com/uploadform.php?user=patarok
Upload any image and then, go to the getdata script:
GetData
http://www.htauditions.com/getdata.php?user=patarok
Which shows the image, the resume and the delete button.
Just a quick security note, don't create files in your server with the
extension .inc, because they are readable by everyone, for example:
connect.inc
http://www.htauditions.com/connect.inc
This shows your password, and this is no good, always rename your
files to .php, if you want to create an include, create an .inc.php.
Regards.
|
Request for Answer Clarification by
galgal1-ga
on
08 Aug 2003 08:27 PDT
Hello,
Thank you for everything. I really am satisfied with what you did. I
have one last question for you and you don't have to answer it if you
think it is too much. I will send you a $25 tip if you don't answer it
by tomorrow morning(which you don't have to). Thank you for everything
and that was awesome.
How can I make the form so that the user can only upload GIF and JPG
files into my server?
Regards,
GalGal
|
Clarification of Answer by
joseleon-ga
on
09 Aug 2003 00:48 PDT
Hello:
I have updated the scripts on your server to allow upload only .JPG
and .GIF files, I have updated the uploadtest.php script adding these
two lines:
$ext = array_pop(explode('.', $form_data_name));
if (($ext!='gif') && ($ext!='GIF') && ($ext!='jpg') && ($ext!='JPG'))
die ('You can only upload GIF or JPG files!!!');
I hope this is what you were looking for.
Regards.
|