Re: [PHP4BETA] unable to upload images with php into Mysql ?

From: Date: Tue, 11 Jan 2000 06:37:11 +0000
Subject: Re: [PHP4BETA] unable to upload images with php into Mysql ?
Groups: php.version4 
Request: Send a blank email to php-version4+get-9027@lists.php.net to get a copy of this message
Try this, it is work with PHP4. <?php switch ($id) { case '101': $uploadpath='./content/programming/'; break; case '102': $uploadpath='./content/os/'; break; case '103': $uploadpath='\\content\\technology\\'; break; default: $uploadpath='\\content\\article\\'; } // ASP-style tags are okay in PHP 3.0.4 and above; some HTML editors recognize these tags // File Upload Script for PHP/3 for Windows // Released under the terms of the public GNU license // Based upon code written by Rasmus Lerdorf and Boaz Yahav // Modified for Windows by Michael Grier // E-mail: bigmike@bigmweb.com // You need to write-enable a directory, named "upload", below the one you place this script in // On Windows NT, you can do this with a DOS program named CACLS // Directions for this can be found at "http://www.bigmweb.com/home/cacls.html" $from1 = "webmaster@your-domain.com"; // you can change this to whatever you want; it's for the From: field of an email notification sent to you $my_addr = "email@email.com"; // change this to your own email address if($action1){ // if files have been uploaded, process them ?> <html> <head> <title>File Upload Results</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> <p><font face="Arial, Helvetica, sans-serif"><font size="+1">File Upload Results</font><br><br> <?php $message1 = ""; $crlf = chr(13) . chr(10); set_time_limit(60); // make reasonably sure the script does not time out on large files $path1 = AddSlashes(dirname($PATH_TRANSLATED)).$uploadpath; for($i = 0; $i < 4; $i++){ // loop through the 4 possible files switch($i){ // retrieve a file pointer from the temp directory case 0: $source = $file1; $source_name = $file1_name; $source_size = $file1_size; break; case 1: $source = $file2; $source_name = $file2_name; $source_size = $file2_size; break; case 2: $source = $file3; $source_name = $file3_name; $source_size = $file3_size; break; case 3: $source = $file4; $source_name = $file4_name; $source_size = $file4_size; break; } if(($source <> "none")&&($source <> "")){ // see if the file exists; non-existing file has name of "none", except in Opera, where it's "" (empty) if($error1 <> 1){ // no need to copy a file if directory not write-enabled $dest = $path1.$source_name; // append file name to our path if(copy($source,$dest)){ // copy the file from the temp directory to the upload directory, and test for success echo $uploadpath; echo "\n$source_name has been uploaded<br>\n"; $message1 = $message1 . $source_name . " -- "; // add filename to message $message1 = $message1 . $source_size . " bytes"; // add filesize to message $message1 = $message1 . $crlf; // add line break } else { echo "Upload directory not write-enabled\n"; // you need to write-enable the upload directory $error1 = 1; // set flag } } unlink($source); // delete the file from the temp directory } } echo "<br><br><a href=\"upload.php\">Back</a>"; $message1 = "Files uploaded by " . $REMOTE_ADDR . $crlf . $crlf . $message1; // mail($my_addr, "Uploaded file list", $message1, "From: $from1\nX-Mailer: PHP/" . phpversion()); } else { // else, prompt for the files // files will be uploaded into the server's temp directory for PHP ?> <html> <head> <title>File Upload</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> <p><font face="Arial, Helvetica, sans-serif"><font size="+1">File Upload</font><br><br> <?php echo $uploadpath; ?> <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 file(s) to upload, then click the &quot;Upload&quot; button. After the files have been uploaded, you will see a results screen.<br><br>Your IP address and the date/time will be recorded to help us identify this upload.<br> <form method="post" enctype="multipart/form-data" action="upload.php"> <input type="hidden" name="MAX_FILE_SIZE" value="400000"> <input type="hidden" name="action1" value="1"> File 1: <input type="file" name="file1" size="30"><br> File 2: <input type="file" name="file2" size="30"><br> File 3: <input type="file" name="file3" size="30"><br> File 4: <input type="file" name="file4" size="30"><br><br> <input type="submit" value="Upload"> </form> </font></p> </body> </html> <?php } ?> --- Absm <abbs@telinco.co.uk> wrote: > abbs@telinco.co.uk > > The following html form uses the php3 script below > and is able to insert the > text and filename into Mysql successfully. The > problem is trying to upload > the corresponding image for the given path on the > server ???? > Also, once an image is chosen by browsing on a local > pc ready for uploading, > the full path to the image gets inserted into Mysql > rather than just the > file name??? > > Where can good scripts be found for uploading direct > from a pc into Mysql??? > and forms and scripts to carry out searches on > Mysql from a web page ??? > > Does the above script have possible security > problems or are there ways to > control such issues or are there better ones > available??? > > Which is the best version of Php that should be used > in terms of least bugs > and its stability??? > > Can someone please help. > > thanks > absm. > abbs@telinco.co.uk > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 > Transitional//EN"> > > <html> > <head> > <title>Untitled</title> > </head> > > <body> > <CENTER>Would you like more information about our > company? > <P> > > <TABLE WIDTH = 400><TR><TD align = right> > > <FORM ACTION="email.php3" METHOD="POST"> > > Year:<BR> > <INPUT TYPE="text" NAME="year" SIZE="20" > MAXLENGTH="30"> > <P> > Make:<BR> > <INPUT TYPE="text" NAME="make" SIZE="20" > MAXLENGTH="30"> > <P> > model<br> > <input type="Text" name="model" size="25"> > <br> > price<br> > <input type="Text" name="price" size="25"> > <br> > picture<br> > <input type="File" name="picture_name" size="25"> > <br><br> > <input type="submit" name="submit" value="Upload"> > </FORM> > > </TD></TR></TABLE></CENTER> > </body> > </html> > > > > > <?/* this script will handle the variables passed > from the moreinfo.html > file */ > /* declare some relevant variables */ > $hostname = "localhost"; > $username = ""; > $password = ""; > $dbName = ""; > > /* MySQL table created to store the data */ > $userstable = ""; > > /* the site administrator's email address */ > $adminaddress = "abbs@telinco.co.uk"; > > /* make connection to database */ > MYSQL_CONNECT($hostname,$username,$password) OR > DIE("Unable to connect to > database"); > > @mysql_select_db("$dbName") or die("Unable to select > database"); > > PRINT "<CENTER>"; > PRINT "Hello, $name."; > PRINT "<BR><BR>"; > PRINT "Thank you for your interest.<BR><BR>"; > PRINT "We will send information to $email, and have > noted that you like > $preference"; > PRINT "</CENTER><BR><BR>"; > > /* Send relevant emails */ > mail("$email", "Your request for information", > "$name\nThank you for your interest!\n > We sell fresh corn daily over the Internet! > Place your order at http://www., > and receive a free package of $preference!"); > > mail("$adminaddress", > "Visitor request for info.", > "$name requested for information.\n > > The email address is $email. \n The visitor prefers > $preference."); > > /* Insert information into table */ > $query = "INSERT INTO $userstable > VALUES('$year','$make','$model','$price','$picture_name')"; > exec( "cp $picture_name > //HostCompany/home/Sitename/www/picture_name"); > $result = MYSQL_QUERY($query); > > echo "year: $year<br>\n"; > echo "make: $make<br>\n"; > echo "model: $model<br>\n"; > echo "price: $price<br>\n"; > echo "temp file: $picture<br>\n"; > echo "file name: $picture_name<br>\n"; > echo "file size: $picture_size<br>\n"; > echo "file type: $picture_type<br>\n"; > echo "<br>\n"; > /*echo "<img src="$picture_name/" border=0 > alt=""><br>\n"; > > > > PRINT "Your information has also been inserted into > our database, for future > reference."; > /* Close the database connection */ > MYSQL_CLOSE(); > ?> > > > > > > > > > > > > > > > > > > > > -- > PHP 4.0 Beta Mailing List > <http://www.php.net/version4/> > To unsubscribe, e-mail: > php4beta-unsubscribe@lists.php.net > For additional commands, e-mail: > php4beta-help@lists.php.net > To contact the list administrators, e-mail: > php4beta-admin@lists.php.net > > __________________________________________________ Do You Yahoo!? Talk to your friends online with Yahoo! Messenger. http://im.yahoo.com

« previous php.version4 (#9027) next »