Code Snippet

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
DivaX007
Guest





PostPosted: Sun Nov 10, 2002 7:59 am    Post subject: Code Snippet Reply with quote

win98, abyss web server(localhost), php
i need to:
1. allow users to to upload images to folder on my server(UploadPics folder)
2. save image path (not the image itself) in mysql
3. display images with php

(i do NOT want to store images in the database. i want to store the path and have the images in a folder, but i don't know how to do this. )

also, the folder that i want the images uploaded to is located at:( 'UploadPics' is the file)

C:\Program Files\Abyss Web Server\htdocs\UploadPics

what do i put for the $uploadpath and
$dest = '';

code snippet:

$uploadpath = '/path/to/store/uploaded/files/';
$source = $HTTP_POST_FILES['file1']['tmp_name'];
$dest = '';


localhost is for testing. i need specific instructions/advice.

thanks in advance.
Back to top
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Mon Nov 11, 2002 12:31 am    Post subject: Re: Code Snippet Reply with quote

DivaX007 wrote:
win98, abyss web server(localhost), php
i need to:
1. allow users to to upload images to folder on my server(UploadPics folder)
2. save image path (not the image itself) in mysql
3. display images with php

(i do NOT want to store images in the database. i want to store the path and have the images in a folder, but i don't know how to do this. )

also, the folder that i want the images uploaded to is located at:( 'UploadPics' is the file)

C:\Program Files\Abyss Web Server\htdocs\UploadPics

what do i put for the $uploadpath and
$dest = '';

code snippet:

$uploadpath = '/path/to/store/uploaded/files/';
$source = $HTTP_POST_FILES['file1']['tmp_name'];
$dest = '';


localhost is for testing. i need specific instructions/advice.

thanks in advance.

The first variable is easy to setup:
Code:

$uploadpath = 'C:\\Program Files\\Abyss Web Server\\htdocs\\UploadPics\\';

But we don't know what is the meaning of $dest so we can't guess what is it correct value. Can you post the entire script so we can have more information about it ?
_________________
Support Team
Aprelium - http://www.aprelium.com


Last edited by aprelium on Mon Nov 11, 2002 2:48 am; edited 1 time in total
Back to top View user's profile Send private message Send e-mail
DivaX007
Guest





PostPosted: Mon Nov 11, 2002 1:54 am    Post subject: entire upload script Reply with quote

<?php if ($HTTP_POST_VARS['action']) { ?>
<HTML>
<HEAD>
<TITLE>File Upload Results</TITLE>
</HEAD>
<BODY BGCOLOR="WHITE" TEXT="BLACK">
<P><FONT FACE="Arial, Helvetica, sans-serif"><FONT SIZE="+1">File Upload
Results</FONT><BR><BR>
<?php

$uploadpath = ;
$source = $HTTP_POST_FILES['file1']['tmp_name'];
$dest = '';

if ( ($source != 'none') && ($source != '' )) {

$imagesize = getimagesize($source);

switch ( $imagesize[2] ) {

case 0:

echo '<BR> Image is unknown <BR>';
break;

case 1:
echo '<BR> Image is a GIF <BR>';
$dest = $uploadpath.uniqid('img').'.gif';
break;

case 2:
echo '<BR> Image is a JPG <BR>';
$dest = $uploadpath.uniqid('img').'.jpg';
break;

case 3:
echo '<BR> Image is a PNG <BR>';
$dest = $uploadpath.uniqid('img').'.png';
break;

}

if ( $dest != '' ) {

if ( move_uploaded_file( $source, $dest ) ) {

echo 'File successfully stored.<BR>';

} else {

echo 'File could not be stored.<BR>';

}

}

} else {

echo 'File not supplied, or file too big.<BR>';

}

?>
<BR><A HREF="<?php echo $PHP_SELF ?>">Back</A>
</FONT></P>
</BODY>
</HTML>
<?php } else { ?>
<!-- File Upload Form HTML Code Here -->

<?php if ($HTTP_POST_VARS['action']) { ?>
<!-- Code to process Uploaded File and Display -->
<!-- The HTML to display the results -->
?>
<BR><A HREF="<?php echo $PHP_SELF ?>">Back</A>
</FONT></P>
</BODY>
</HTML>
<?php } else { ?>
<HTML>
<HEAD>
<TITLE>File Upload</TITLE>
</HEAD>
<BODY BGCOLOR="WHITE" TEXT="BLACK">
<P><FONT FACE="Arial, Helvetica, sans-serif"><FONT SIZE="+1">File
Upload</FONT><BR><BR>

<!--If your browser is upload-enabled, you will see &quot;Browse&quot; (Netscape,
Internet Explorer), or &quot;...&quot; (Opera) buttons below. Use them to
select files to upload, then click the &quot;Upload&quot; button. After the
files have been uploaded, you will see a results screen.<BR>-->

<FORM METHOD="POST" ENCTYPE="multipart/form-data"
ACTION="<?php echo $PHP_SELF;?>">

<INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="800000">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="1">
File 1: <INPUT TYPE="FILE" NAME="file1" SIZE="50"><BR><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>
</FONT></P>
</BODY>
</HTML>
<?php } ?>
Back to top
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Mon Nov 11, 2002 2:53 am    Post subject: Re: Code Snippet Reply with quote

You should only set $uploadpath as described in our earlier post. $dest must be left as is because it is an internal variable not intented to be a parameter.

By the way, the code you gave us has unbalanced { and } which results in parsing errors.

The following is the fixed version:

Code:

<?php if ($HTTP_POST_VARS['action']) { ?>
<HTML>
<HEAD>
<TITLE>File Upload Results</TITLE>
</HEAD>
<BODY BGCOLOR="WHITE" TEXT="BLACK">
<P><FONT FACE="Arial, Helvetica, sans-serif"><FONT SIZE="+1">File Upload
Results</FONT><BR><BR>
<?php

$uploadpath = 'C:\\Program Files\\Abyss Web Server\\htdocs\\UploadPics\\';
$source = $HTTP_POST_FILES['file1']['tmp_name'];
$dest = '';

if ( ($source != 'none') && ($source != '' )) {

$imagesize = getimagesize($source);

switch ( $imagesize[2] ) {

case 0:

echo '<BR> Image is unknown <BR>';
break;

case 1:
echo '<BR> Image is a GIF <BR>';
$dest = $uploadpath.uniqid('img').'.gif';
break;

case 2:
echo '<BR> Image is a JPG <BR>';
$dest = $uploadpath.uniqid('img').'.jpg';
break;

case 3:
echo '<BR> Image is a PNG <BR>';
$dest = $uploadpath.uniqid('img').'.png';
break;

}

if ( $dest != '' ) {

if ( move_uploaded_file( $source, $dest ) ) {

echo 'File successfully stored.<BR>';

} else {

echo 'File could not be stored.<BR>';

}

}

} else {

echo 'File not supplied, or file too big.<BR>';

}

?>
<BR><A HREF="<?php echo $PHP_SELF ?>">Back</A>
</FONT></P>
</BODY>
</HTML>
<?php } else { ?>
<!-- File Upload Form HTML Code Here -->

<?php if ($HTTP_POST_VARS['action']) { ?>
<!-- Code to process Uploaded File and Display -->
<!-- The HTML to display the results -->

<BR><A HREF="<?php echo $PHP_SELF ?>">Back</A>
</FONT></P>
</BODY>
</HTML>
<?php } else { ?>
<HTML>
<HEAD>
<TITLE>File Upload</TITLE>
</HEAD>
<BODY BGCOLOR="WHITE" TEXT="BLACK">
<P><FONT FACE="Arial, Helvetica, sans-serif"><FONT SIZE="+1">File
Upload</FONT><BR><BR>

<!--If your browser is upload-enabled, you will see &quot;Browse&quot; (Netscape,
Internet Explorer), or &quot;...&quot; (Opera) buttons below. Use them to
select files to upload, then click the &quot;Upload&quot; button. After the
files have been uploaded, you will see a results screen.<BR>-->

<FORM METHOD="POST" ENCTYPE="multipart/form-data"
ACTION="<?php echo $PHP_SELF;?>">

<INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="800000">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="1">
File 1: <INPUT TYPE="FILE" NAME="file1" SIZE="50"><BR><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>
</FONT></P>
</BODY>
</HTML>
<?php }  } ?>

Notice that we remove an extra ?> and added an extra } at the end.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
DivaX007
Guest





PostPosted: Mon Nov 11, 2002 3:28 am    Post subject: Thank you Reply with quote

thank you, thank you, thank you

[i can not copy and paste 'thank you' enough times to express my gratitude]


you guys are tops!!!! :D 8)
Back to top
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Mon Nov 11, 2002 11:03 pm    Post subject: Re: Thank you Reply with quote

DivaX007 wrote:
thank you, thank you, thank you

[i can not copy and paste 'thank you' enough times to express my gratitude]


you guys are tops!!!! :D 8)

:D It's normal to help, it is our job .
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
Barhopper
Guest





PostPosted: Wed Jan 01, 2003 8:31 pm    Post subject: Reply with quote

If your intrested I wrote a very simple and easy to you use upload script, so if you want it let me know.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group