SkyRanger Posted April 26, 2007 Share Posted April 26, 2007 How would I be able to add more extensions to this: if ($_FILES['imagefile']['type'] == "image/gif"){ copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name']) } Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/ Share on other sites More sharing options...
sw0o0sh Posted April 26, 2007 Share Posted April 26, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-238692 Share on other sites More sharing options...
SkyRanger Posted April 26, 2007 Author Share Posted April 26, 2007 Not letting me call the function: Fatal error: Call to undefined function is_image() in membersfiles.php on line 71 Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-238728 Share on other sites More sharing options...
SkyRanger Posted April 26, 2007 Author Share Posted April 26, 2007 ~bump~ Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-238762 Share on other sites More sharing options...
sw0o0sh Posted April 26, 2007 Share Posted April 26, 2007 then you didnt declare the function i included >_> Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-238775 Share on other sites More sharing options...
SkyRanger Posted April 26, 2007 Author Share Posted April 26, 2007 Yeah i declared it, my head is full of function problems tonight, got 90% of them fixed, will fix the other 10% in the morning. Thanks sw0o0sh. Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-238810 Share on other sites More sharing options...
sw0o0sh Posted April 26, 2007 Share Posted April 26, 2007 So wait, is your problem fixed or do you still need help? It would only say that error if that function did not exist at least ABOVE the area where the function is being called. Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-238811 Share on other sites More sharing options...
SkyRanger Posted April 26, 2007 Author Share Posted April 26, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-238814 Share on other sites More sharing options...
SkyRanger Posted April 26, 2007 Author Share Posted April 26, 2007 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>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-238974 Share on other sites More sharing options...
AndyB Posted April 26, 2007 Share Posted April 26, 2007 remove the ; from the preceding line, i.e. copy(.....) or die(...); Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-238988 Share on other sites More sharing options...
SkyRanger Posted April 26, 2007 Author Share Posted April 26, 2007 That fixed it, thanks AndyB Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-238996 Share on other sites More sharing options...
SkyRanger Posted April 26, 2007 Author Share Posted April 26, 2007 Found a problem, I tried adding 2 more case switches but they are not working: case "image/png": return true; break; case "image/jpg": return true; break; Not sure what the problem is. Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-239060 Share on other sites More sharing options...
SkyRanger Posted April 26, 2007 Author Share Posted April 26, 2007 ~bump~ Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-239123 Share on other sites More sharing options...
SkyRanger Posted April 26, 2007 Author Share Posted April 26, 2007 ~bump~ Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-239163 Share on other sites More sharing options...
SkyRanger Posted April 26, 2007 Author Share Posted April 26, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-239241 Share on other sites More sharing options...
SkyRanger Posted April 26, 2007 Author Share Posted April 26, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-239293 Share on other sites More sharing options...
MadTechie Posted April 26, 2007 Share Posted April 26, 2007 erm. simplely they won't return false, and bumping like that is a pain, i sometimes wait a day before bumping atleast an hour but 3 hours works well as a different set of people are normally online Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-239325 Share on other sites More sharing options...
SkyRanger Posted April 26, 2007 Author Share Posted April 26, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-239330 Share on other sites More sharing options...
MadTechie Posted April 26, 2007 Share Posted April 26, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-239335 Share on other sites More sharing options...
SkyRanger Posted April 26, 2007 Author Share Posted April 26, 2007 Working now...lol, I added that code and found the problem. It was a coder error. Thanks MadTechie Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-239341 Share on other sites More sharing options...
MadTechie Posted April 26, 2007 Share Posted April 26, 2007 welcome, Quote Link to comment https://forums.phpfreaks.com/topic/48713-solved-add-extension/#findComment-239346 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.