|
|
|
| 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 : |
6110 |
| 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 | | | usercounter class Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables | | | Display a bar chart based on random values. Categories : Graphics, PHP, GD image library, Charts and Graphs | | | Pull deliniated text strings into a "SELECT" statement in a form. Categories : HTML and PHP, PHP, Strings | | | TABLE LIST, DATABASE LIST, PHP , PostgreSQL, ADMIN, Web Interface,
database admin Categories : PHP, PostgreSQL | | | String Replacement and speed consideration
Categories : PHP, Strings, Regexps | | | Most of the browsers, especially Internet Explorer, behave in different ways. Hence it become necessary to use Browser detection to fix the non standard behavior of the browser. This is a browser sniffer class that can be used for the above purpose. Categories : PHP, PHP Classes, Browsers | | | shmop_close -- Close shared memory block Categories : PHP, PHP Functions, shmop | | | Three Cool Classes and One Trick Categories : PHP, PHP Classes, Graphics, Email | | | Print out array key => value in colored HTML Categories : PHP, Arrays, HTML and PHP | | | Handle multiple file upload Categories : Complete Programs, Filesystem, PHP, HTML and PHP | | | Directory viewer, customize how you display the file structure, easy to
understand. Found out about PHP 3 days ago, and this is my first prog. Categories : HTML and PHP, Complete Programs, Directories, Filesystem, PHP | | | PhpIBadmin - Web interface to Interbase RBDMS , this is a port of
phpMyadmin Categories : Databases, InterBase, PHP | | | PHP-MySQL shopping cart
Categories : PHP, Ecommerce, Complete Programs | | | XMLManipulation Categories : PHP, XML, SimpleXML | |
| |
| | | | | Eduardo Dias wrote :617
mova para o if do copy a linha:
print "The image that was uploaded, $Image1, was copied to $Image1Final.";
...
| |
|
|