Forum Moderators: coopster
<?php
if (($_FILES["file"]["type"] == "image/gif")
¦¦ ($_FILES["file"]["type"] == "image/jpeg")
&& ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
postscript: For any of you interested in the background of what I'm trying to do continue reading:
I have gotten tripped up again by GoDaddy's obstacle course of limitations. Now it turns out I can't create an image upload field on my forms because to upload an image their server must make an outside connection which they've denied. I did managed to push a little further by using cURL and although I was able to establish FTP connections to my own servers I could not upload files to them regardless of what permissions I had set.
So my mixed up plan now is to allow files to be uploaded to where I am hosted and run a script / application on one of my local servers to retrieve the files from the specified folder at regular intervals using ftp...from there I will try to work out a method (maybe applescript on one of the mac computers) to send an email with the downloaded files attached. You see, that's all I really want: to allow clients the ease of connecting to the website and attach their files so I can recieve them either on my local FTP server or even through my email. I just don't want to send my clients to their email to send me files. It's just my preference.
ANY SOLUTIONS? COMMENTS? ETC? ALL ARE WELCOMED!
However instead of writing long if I would choose either switch:
switch($_FILES["file"]["type"]){
case "image/gif":
case "image/jpeg":
...
$type = "accepted";
break;
default: $type = "not accepted";
or in_array:
$accepted = array("image/gif", "image/jpeg");
if(in_array($_FILES["file"]["type"], $accepted)) $type="accepted";
else $type = "not accepted";
Hope this helps you
Regards
Michal