Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP QUESTION TO UPLOAD JPEGS TO SERVER

Status
Not open for further replies.

dadms

Technical User
Mar 8, 2003
67
US
Is it possible to make a form or something similar that allows users to upload files into the server without having them FTP it? If so any suggestions where I could start looking?
 
Yes it is possible.

Where to look? GOOGLE is your best friend.

Google this: upload with php


"Hey...Where are all the chicks?" -- unknown
 
in the form use the file input box:
[blue]
Code:
<form method=&quot;post&quot; action=&quot;myscript.php&quot; enctype=&quot;multipart/form-data&quot;>
<input type=&quot;file&quot; name=&quot;images&quot;>
</form>
[/blue]
You can then manipulate the image using php's built in array thingy ie:

[blue]$_FILES['images'][/blue]

MrBelfry
 
thank you for the many suggestions.
 
I've seen a load of questions around uploading images lately. Does someonw have as assesment due in ??
 
I've seen a load of questions around uploading images lately. Does someonw have as assesment due in ??

Not me.. I'm not even in school. Plus I graduated already from both High School, and College.

Maybe it's just a coincidence that everyone is asking similar questions around the same time.

&quot;Hey...Where are all the chicks?&quot; -- unknown
 
Code:
function uploadFile() {
        // import form data into local function
        global $ulFile, $ulFile_name, $ulFile_type;
        
        // check for form data
        if (isset($ulFile) && $ulFile_name) {
                // check uploaded file is one of supported types
                if ($ulFile_type == &quot;image/png&quot; ||
                                $ulFile_type == &quot;image/jpeg&quot; ||
                                $ulFile_type == &quot;image/pjpeg&quot;) { 
                        
                        $fn = getUniqueName($ulFile_name); // generate a unique file name
        
                        /* move file to the photo directory. Notice we now use move_uploaded_file
                         * instead of copy. It includes a check to make sure the file came from
                         * the right source, making it more secure
                        */
                        if (move_uploaded_file($ulFile, PHOT_DIR.&quot;/$fn&quot;)) {
                                print &quot;<p>$ulFile_name successfully uploaded</p>\n&quot;;
                                saveThumbnail($fn); // generate tumbnail image
                        } else {
                                print &quot;<p>Oops! Couldn't upload $ulFile_name</p>\n&quot;;
                                unlink($ulFile); // remove temporary file
                        }
                } else {
                        print &quot;<p>Sorry, file type $ulFile_type not supported. Try a JPEG or PNG image.</p>\n&quot;;
                        unlink($ulFile); // remove temporary file
                }
        }
}
--------------------------------------------------------------------------------

and the form code 


<?php
        /* album.php - version 3
         * .net magazine ([URL unfurl="true"]www.netmag.co.uk),[/URL] issue 83
         * Matt Kynaston, 2001
         * Distributed under the GNU Public License - [URL unfurl="true"]www.gnu.org/copyleft/gpl.html[/URL]
         *
         * The PHP Photo Album displays the contents of a thumbnail directory,
         * linked to full size images in the photo directory. It gives the user
         * the opportunity to upload their own photos to the album, automatically
         * creating tumbnails.
         *
         * Requires PHP4 with the GD and ZLIB extensions installed (php_gd.dll and php_zlib.dll
         * on Windows). These are available from the full download of PHP at [URL unfurl="true"]www.php.net[/URL]
         * Modify your php.ini file (C:\WINDOWS\PHP.INI in Windows systems) to point at them
        */
         
        /* constant declaration section
         * change these to modify the album directories or image sizes
        */
        define(&quot;NUM_COLS&quot;, 4); // number of columns in table
        define(&quot;PHOT_DIR&quot;, &quot;photos&quot;); // photo directory, relative to this page
        define(&quot;THUMB_DIR&quot;, &quot;thumbs&quot;); // thumbnail directory, relative to this page
        define(&quot;MAX_XY&quot;, 150); // maximum width or height of thumbnail image

        /* all the functions used on this page have been split off into a 
         * seperate file. The include statement below makes them available to this
         * page.
        */
        include(&quot;album_functions.php&quot;); 

?>
<html>
<head>
<title>Photo Album</title>
<link href=&quot;album.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;>
</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<h1>PHP Photo Album</h1>
<h3>(final version)</h3>

<?php uploadFile() ?>

<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;<?php print $PHP_SELF?>&quot; enctype=&quot;multipart/form-data&quot;>
  <p>Add your own image to the album:<br>
    <input type=&quot;file&quot; name=&quot;ulFile&quot;>
        <input type=&quot;hidden&quot; name=&quot;MAX_FILE_SIZE&quot; value=&quot;512000&quot;>
  </p>
  <p>
    <input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Upload&quot;>
  </p>
</form>

<p> </p>

<?php makeAlbumTable(); ?>

</body>
</html>

Bastien

Any one have a techie job in Toronto, I need to work...being laid off sucks!
 
thanks for all the information. i have graduated from hi-school and college as well. i want for other co-workers to be able to upload .pdf and .jpeg without having to email them to me to upload.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top