Jump to content

[SOLVED] Add Extension


SkyRanger

Recommended Posts

um, a function or a very long OR statement...

 

<?PHP
function is_image($input){

switch($input){

case "image/gif":
return true;
break;

case "image/jpeg":
return true;
break;

default:
return false; // Not an image, or at least didnt match what you made availab le
break;

}

}

if (is_image($_FILES['imagefile']['type']) == TRUE){ 

copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name']);
} 

?>

 

That's how I'd approach it. Not sure if theres a cleaner / shorter method.

Link to comment
Share on other sites

No the problem is still there i put the:

 

function is_image($input){

switch($input){

case "image/gif":
return true;
break;

case "image/jpeg":
return true;
break;

default:
return false; // Not an image, or at least didnt match what you made availab le
break;

}

}

 

Into my functions.php doc with the rest of my garbage...lol

 

I put:

I replaced:

if ($_FILES['imagefile']['type'] == "image/gif"){ 
copy ($_FILES['imagefile']['tmp_name'], "files/images/".$_FILES['imagefile']['name']) 

or die ("Could not copy"); 
echo "<br>"; 


with:
   
if (is_image($_FILES['imagefile']['type']) == TRUE){ 
copy ($_FILES['imagefile']['tmp_name'], "files/images/".$_FILES['imagefile']['name']);

or die ("Could not copy"); 
echo "<br>"; 


} -- Is farther down around rest of code

 

I must have missed a step somewhere.

 

It is 12:30am here so eyes are closing will look at it again in morning and will set as Solved if this works.

 

Link to comment
Share on other sites

Ok, I am getting a new error now:

 

Parse error: syntax error, unexpected T_LOGICAL_OR in /home/prodco/public_html/members/membersfiles.php on line 81


which is:

    or die ("Could not copy"); 

This is what I have so far:

if(isset( $Submit ))
{
//If the Submitbutton was pressed do:

if (is_image($_FILES['imagefile']['type']) == TRUE){ 
copy ($_FILES['imagefile']['tmp_name'], "files/images/".$_FILES['imagefile']['name']);

    or die ("Could not copy"); 
echo "<br>"; 
     
	$filename = $_FILES['imagefile']['name'];
	$owner = $logged;

	include "inc/dbinfo.inc.php";
// database connect script.
$connection=mysql_connect ("$dblocation", "$dbusername", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error());
        mysql_select_db ("$dbname");

$sql = "INSERT INTO memberimages VALUES ('', '".$filename."', '".$owner."', '".$desc."')";
$result = mysql_query($sql) or die ('I could not add information to the database because ' . mysql_error());

		    
        echo "Name: ".$_FILES['imagefile']['name']."<br>"; 
        echo "Size: ".$_FILES['imagefile']['size']."<br>"; 
        echo "Type: ".$_FILES['imagefile']['type']."<br>"; 
        echo "Image Upload Completed"; 
        } 
	else {
            echo "<br><br>";
            echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
        }
} 

Link to comment
Share on other sites

I added PNG and JPG to my functions.php but when I try to upload a file with either one of these extension it says no allowed.

 

function is_image($input){

switch($input){

case "image/gif":
return true;
break;

case "image/jpeg":
return true;
break;

case "image/png": //Added for allow
return true;
break;

case "image/jpg": //Added for allow
return true;
break;

default:
return false; // Not an image, or at least didnt match what you made available
break;

}

}

 

Why is this not allowed.

 

Here is the form code:

 

<form name="form1" method="post" action="" enctype="multipart/form-data">
		<input name="desc" type="text" value="" size="30" />
<input type="file" name="imagefile">
<br>
<input type="submit" name="Submit" value="Submit"> 
<?
if(isset( $Submit ))
{
//If the Submitbutton was pressed do:

if (is_image($_FILES['imagefile']['type']) == TRUE){ 
copy ($_FILES['imagefile']['tmp_name'], "files/images/".$_FILES['imagefile']['name'])

    or die ("Could not copy"); 
echo "<br>"; 
    
	$uploaddate = date("l F j, Y"); 
	$filename = $_FILES['imagefile']['name'];
	$owner = $logged;

	include "inc/dbinfo.inc.php";
// database connect script.
$connection=mysql_connect ("$dblocation", "$dbusername", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error());
        mysql_select_db ("$dbname");

$sql = "INSERT INTO memberimages VALUES ('', '".$filename."', '".$owner."', '".$desc."', '".$uploaddate."')";
$result = mysql_query($sql) or die ('I could not add information to the database because ' . mysql_error());

		    
        echo "Name: ".$_FILES['imagefile']['name']."<br>"; 
        echo "Size: ".$_FILES['imagefile']['size']."<br>"; 
        echo "Type: ".$_FILES['imagefile']['type']."<br>"; 
        echo "Image Upload Completed"; 
        } 
	else {
            echo "<br><br>";
            echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
        }
} 
?></form>

Link to comment
Share on other sites

Anybody able to tell my why when I upload an image and the following to switch cases are in my functions.php file :

 

case "image/png": //Added for allow
return true;
break;

case "image/jpg": //Added for allow
return true;
break;

 

is saying that the image is false?

Link to comment
Share on other sites

Sorry MadTechie, was getting frustrated and working on 3 different codes at the same time, usually I wait for a couple of hours before bumping guess I got to impatient.  Will have to double check code to find out why they are doing that, maybe I missed something.  Thanks

Link to comment
Share on other sites

ok for testing

 


function is_image($input){

switch($input){

case "image/gif":
return true;
break;

case "image/jpeg":
return true;
break;

case "image/png": //Added for allow
return true;
break;

case "image/jpg": //Added for allow
return true;
break;

default:
die($input);// ADD THIS
return false; // Not an image, or at least didnt match what you made available
break;

}

}

 

this should tell you whats going wrong

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.