|
|
|
| Title : |
Check to see whether the type of file the user uploaded is a valid image type to upload.
|
| Categories : |
PHP |
 Michael Stearne |
| Date : |
Dec 27th 1999 |
| Grade : |
2 of 5 (graded 1 times) |
| Viewed : |
5299 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Michael Stearne |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
/////// Check to see whether the type of file the user uploaded is a valid image type to upload
////// Michael Stearne
<?
function checkImgType($image_type,$image_name){
if((strcmp($image_type,"image/jpeg")==0)||(strcmp($image_type,"image/gif")==0)||
(strcmp($image_type,"image/pjpeg")==0)||(strcmp($image_type,"image/jpg")==0))
{
switch($image_type){
case "image/jpg":
$imageExt=".jpg";
break;
case "image/jpeg":
$imageExt=".jpg";
break;
case "image/pjpeg":
$imageExt=".jpg";
break;
case "image/gif":
$imageExt=".gif";
break;
}
return $imageExt;
}else
{
print "<b><font color=red>$image_name is not a valid file to upload.<br>
Please upload JPEG (.jpg) or GIF (.gif) type images only.</font></b><br> <br>";
return 0;
}
}
///////////////////////
$ABS_IMAGES_DIR="/www/htdocs/site/images/";
if($Image1!="none"){
$Image1Ext=checkImgType($Image1_type,$Image1_name);
}
if($Image1Ext=='0'){
echo '<br><div align="center"><b><blink>Please press back on your browser to correct the image(s).</
blink></b></div>';
exit();
}
if($Image1!="none"){
$Image1Final=$ABS_IMAGES_DIR."NewNameForImage1".$Image1Ext;
copy($Image1, $Image1Final);
}
print "The image that was uploaded, $Image1, was copied to $Image1Final.";
----------------------------------------------
The form would look like:
<form action="TheFileTheStuffAboveIsIn.php3" enctype="multipart/form-data" method=post>
<input type="file" name="Image1" size="10">
<input type=submit>
</form>
|
|
| Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | PHP-CSL PHP Code Snippet Library, A very handy application designed to save you many hours by storing all your code snippets, classes and functions. Categories : PHP, Utilities, MySQL, Databases, To PHP | | | Popup window creator for images on the Fly. Categories : PHP, GD image library, Java Script | | | phpMyAdmin is intended to handle the adminstration of MySQL
over the web. Categories : Databases, MySQL, Complete Programs, PHP | | | Simple database class Categories : PHP, PHP Classes, MySQL, Databases | | | Persistent connections - General information. Categories : General SQL, PHP, Databases | | | ECHO-PHP Class Real Time Transaction Processor v1.4.4 for Credit Cards and
Checks / ACH Categories : PHP Classes, Cybercash, Classes and Objects, Ecommerce, PHP | | | Getting newsgroup with PHP Categories : PHP, IMAP | | | Alert in JavaScript and Trace in Flash Action script are two commands that I find very much useful for tracking and debugging errors in my scripts. Unfortunately, there is no such option in PHP. Categories : PHP, Java Script, Debugging | | | a smart list board on index for use for communication Categories : MS SQL Server, PHP | | | AJAX Application Categories : PHP, AJAX, Databases, MySQL | | | Link Manager for Link Exchangers Categories : PHP, PHP Classes, Databases, MySQL, CURL | | | PHP interface class to the eBusiness Charts generatation remote service. Categories : PHP, PHP Classes, Graphics, Charts and Graphs | | | I need a trim function/regexp that will trim all " " from the ends of a string. Categories : Regexps, PHP, Strings | | | Local-to-user date and time display regardless of time zone or where the website's server is located Categories : PHP, Date Time, HTML and PHP, Java Script | |
| | | | Eduardo Dias wrote :617
mova para o if do copy a linha:
print "The image that was uploaded, $Image1, was copied to $Image1Final.";
...
| |
|
|