emediastudios
-
Posts
418 -
Joined
-
Last visited
Posts posted by emediastudios
-
-
I have been using this code for a few sites i have built for the mail function.
<?php ini_set ("SMTP","mail.bigpond.com.au"); ini_set ("sendmail_from","my@email.com"); $EmailFrom = Trim(stripslashes($_POST['email'])); $EmailTo = "sales@goldproperty.com.au"; $Subject = "GCProperty Online Enquiry"; $First = Trim(stripslashes($_POST['First'])); $email = Trim(stripslashes($_POST['email'])); $PostCode = Trim(stripslashes($_POST['PostCode'])); $Tel = Trim(stripslashes($_POST['Tel'])); $time = Trim(stripslashes($_POST['time'])); $emailcontact = Trim(stripslashes($_POST['emailcontact'])); $phonecontact = Trim(stripslashes($_POST['phonecontact'])); $comments = Trim(stripslashes($_POST['comments'])); ?>
I dont want this to continue, as my email account will be hammered with traffic.
I want to use another method, like CGI, how would i do that?
-
I know its got to be an edit in the area of my code here
if($copy) { print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">"; //Writes the information to the database mysql_query("INSERT INTO `employees` VALUES ('$name', '$suburb', '$price', '$content', '$content2','$agentmobile', '$agentemail','$uploadFile0','$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')") ; }else{ echo "<br>$file_name The File(s) could not be uploaded!<br>The file must be under 1 meg and be of a valid extension type, jpeg, jpg, png or gif!<br /> <br /> Please go <a href=\"property_add.php\">back</a> and try again";
If ($copy)
I need a check like, if $copy all files then return true, else error
-
Hi Everyone
I have this code that works perfectly thanks to alot of help on PHPFreaks.
But there is one problem.
If i upload multible images and (1) or more of those files is not of valid image size, type or the file exists, it still inserts a record.
I want the code to not allow insert record if one or more of the image upload fails.
In a nutshell, If one fails, all fail and dont insert record.
I'll be happy with that.
Code below
<?php //This is the directory where images will be saved $path = '../images/'; //This gets all the other information from the form $name=$_POST['name']; $suburb=$_POST['suburb']; $price=$_POST['price']; $content=$_POST['content']; $content2=$_POST['content2']; $agentmobile=$_POST['agentmobile']; $agentemail=$_POST['agentemail']; $uploadFile0=($_FILES['uploadFile0']['name']); $uploadFile1=($_FILES['uploadFile1']['name']); $uploadFile2=($_FILES['uploadFile2']['name']); $uploadFile3=($_FILES['uploadFile3']['name']); $uploadFile4=($_FILES['uploadFile4']['name']); $uploadFile5=($_FILES['uploadFile5']['name']); $uploadFile6=($_FILES['uploadFile6']['name']); $uploadFile7=($_FILES['uploadFile7']['name']); $uploadFile8=($_FILES['uploadFile8']['name']); // Connects to your Database mysql_connect("localhost", "root", "*********") or die(mysql_error()) ; mysql_select_db("gcproperty") or die(mysql_error()) ; // Uploads Images $uploadNeed = $_POST['uploadNeed']; // start for loop for($x=0;$x<$uploadNeed;$x++) { $file_name = $_FILES['uploadFile'. $x]['name']; //test $Size = $_FILES['uploadFile'. $x]['size']; //Test Check $Valid = false; if(valid_ext($file_name)) { echo "valid ext"; $Valid = true; }else{ echo "invalid Type"; } echo "<br>"; if(valid_size($Size)) { echo "valid size"; }else{ $Valid = false; echo "invalid Size"; } if($Valid) { // strip file_name of slashes $file_name = stripslashes($file_name); $file_name = str_replace("'","",$file_name); if(file_exists($path . $file_name) ) { echo "<br>The file {$file_name} already exists."; }else { $copy = move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'], $path . $file_name); } } } // check if successfully copied if($copy) { print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">"; //Writes the information to the database mysql_query("INSERT INTO `employees` VALUES ('$name', '$suburb', '$price', '$content', '$content2','$agentmobile', '$agentemail','$uploadFile0','$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')") ; }else{ echo "<br>$file_name The File(s) could not be uploaded!<br>The file must be under 1 meg and be of a valid extension type, jpeg, jpg, png or gif!<br /> <br /> Please go <a href=\"property_add.php\">back</a> and try again"; } // end of loop //***FUNCTIONS //filter extensions function valid_ext($file_name) { $valid = array("jpeg","jpg","png","gif"); $extension = strtolower(substr($file_name,-3,3)); return (in_array($extension, $valid)); } //filter by size, function valid_size($size) { return ($size <= 1048576); } ?>
Thanks
-
With the last code you supplied me, as with the first, if i attempt to upload more than one file, say 4 images and i zip file or non image file, it uploads all the valid files and not the invalid files but still inserts the record into my database,
Is there a way that if one file is not of valid ext or valid size that it does not upload anything, and doesnt insert a record?
Thanks Super Guru
-
cant find the missing (s) 0n errors.
I will have upcoming payed PHP sites to make in the future,
May need some help, would like to rely on you,
Will pay you of course.
-
Like a charm.
;)
Thanks man, your going to be a weathy man one day.
Your very smart.
-
You live up to your name "Super Guru"
Absolute Genuis.
You have solved my problem(s)
Just one last thing, dont mean to ask to much But on the bottom of my code where it says "Please go back and try agian"
How can i make that an active link to "property_add.php.
Thanks for everything, cant say how much you have helped.
-
Your a champ super Guru.
Works!!!
Ive been on this for weeks.
Only one thing, it still copies the file if it is of invalid ext but is of valid size.
It echo's correctly and reconizes the file if is valid or invalid in all categories, size, ext, and file exsists.
Can i get the code to stop processing the rest of the code when returns invalid?
Like ( if invalid ext or invalid size print url (error.php) and stop proceessing rest of code?)
Thanks for your help, i am stoked!!
-
Thanks for that, i added your code but it echo,s file extension invalid when it is and echo,s valid size when it isnt ???
What would be the best way to implement your code in mine?
Here is mine
<?php //This is the directory where images will be saved $path = '../images/'; //This gets all the other information from the form $name=$_POST['name']; $suburb=$_POST['suburb']; $price=$_POST['price']; $content=$_POST['content']; $content2=$_POST['content2']; $agentmobile=$_POST['agentmobile']; $agentemail=$_POST['agentemail']; $uploadFile0=($_FILES['uploadFile0']['name']); $uploadFile1=($_FILES['uploadFile1']['name']); $uploadFile2=($_FILES['uploadFile2']['name']); $uploadFile3=($_FILES['uploadFile3']['name']); $uploadFile4=($_FILES['uploadFile4']['name']); $uploadFile5=($_FILES['uploadFile5']['name']); $uploadFile6=($_FILES['uploadFile6']['name']); $uploadFile7=($_FILES['uploadFile7']['name']); $uploadFile8=($_FILES['uploadFile8']['name']); // Connects to your Database mysql_connect("localhost", "root", "5050888202") or die(mysql_error()) ; mysql_select_db("gcproperty") or die(mysql_error()) ; // Uploads Images $uploadNeed = $_POST['uploadNeed']; // start for loop for($x=0;$x<$uploadNeed;$x++){ $file_name = $_FILES['uploadFile'. $x]['name']; // strip file_name of slashes $file_name = stripslashes($file_name); $file_name = str_replace("'","",$file_name); if(file_exists($path . $file_name) ) { echo "The file {$file_name} already exists."; } else { $copy = move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'], $path . $file_name); } } // check if successfully copied if($copy){ print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">"; //Writes the information to the database mysql_query("INSERT INTO `employees` VALUES ('$name', '$suburb', '$price', '$content', '$content2','$agentmobile', '$agentemail','$uploadFile0','$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')") ; } else{ echo "$file_name The File(s) could not be uploaded!<br>The file must be under 1 meg and be of a valid extension type, (jpeg, ,jpe, jpg, png or gif!<br /> <br /> Please go back and try agian"; } // end of loop ?>
I changed your code to look like this, is this right?
<?php //test $Name = $_FILES['uploadFile'. $x]['name']; $Size = $_FILES['uploadFile'. $x]['size']; ?>
-
change
if(file_exists($path . $file_name) || !valid_ext($file_name)) {
to
if(file_exists($path . $file_name) ) {
*note, i haven't read the whole thread
Awesome ;D
Thats my check if file exists problem fixed.
Now file size and type.
I have this as a image size filter.
//filter by size, function valid_size() { if($_FILES['uploadFile'. $x]['name']['size'] > 1048576) return FALSE; //Over one mega else return TRUE; }
does not work, any ideas?
Thanks 4 ur help
-
.... You never check if the file exists... You have the functions in there, but you never use them...
for($x=0;$x<$uploadNeed;$x++){ $file_name = $_FILES['uploadFile'. $x]['name']; // strip file_name of slashes $file_name = stripslashes($file_name); $file_name = str_replace("'","",$file_name); $copy = move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'], $path . $file_name); }
That never checks if the file exists....
Something like the following should work:
for($x=0;$x<$uploadNeed;$x++){ $file_name = $_FILES['uploadFile'. $x]['name']; // strip file_name of slashes $file_name = stripslashes($file_name); $file_name = str_replace("'","",$file_name); if(file_exists($path . $file_name) || !valid_ext($file_name)) { echo "The file {$file_name} already exists."; } else { $copy = move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'], $path . $file_name); } }
Also, copy is only set to hold the value of the last move, so if the last one moves correctly and the first 8 don't then the if($copy) idea is defeated entirely.
I did this and had a play around and it works a little, Tells me if the file exists and i get an error i have echo'd, but if the file doesnt exist in continues on with readind th code and i get this error.
Fatal error: Call to undefined function valid_ext() in C:\Program Files\Apache Group\Apache2\htdocs\gcproperty\admin\add_test.php on line 38
-
Please has anyone a solution?
Love to get this sorted. ???
-
Thats the only filter that works at this stage.
The image size filter. image type, and check if file exists doesnt :'(
-
I have gone all day on this one and it is driving me crazy>..Please someone.
My Code
<?php //This is the directory where images will be saved $path = '../images/'; //This gets all the other information from the form $name=$_POST['name']; $suburb=$_POST['suburb']; $price=$_POST['price']; $content=$_POST['content']; $content2=$_POST['content2']; $agentmobile=$_POST['agentmobile']; $agentemail=$_POST['agentemail']; $uploadFile0=($_FILES['uploadFile0']['name']); $uploadFile1=($_FILES['uploadFile1']['name']); $uploadFile2=($_FILES['uploadFile2']['name']); $uploadFile3=($_FILES['uploadFile3']['name']); $uploadFile4=($_FILES['uploadFile4']['name']); $uploadFile5=($_FILES['uploadFile5']['name']); $uploadFile6=($_FILES['uploadFile6']['name']); $uploadFile7=($_FILES['uploadFile7']['name']); $uploadFile8=($_FILES['uploadFile8']['name']); // Connects to your Database mysql_connect("localhost", "root", "5050888202") or die(mysql_error()) ; mysql_select_db("gcproperty") or die(mysql_error()) ; $uploadNeed = $_POST['uploadNeed']; // start for loop for($x=0;$x<$uploadNeed;$x++){ $file_name = $_FILES['uploadFile'. $x]['name']; // strip file_name of slashes $file_name = stripslashes($file_name); $file_name = str_replace("'","",$file_name); $copy = move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'], $path . $file_name); } //filter extensions function valid_ext($file_name) { $valid = array("jpeg","jpg","jpe","png","gif"); $extension = strtolower(substr(strrchr($file_name,"uploadFile".$x),1)); if(in_array($extension, $valid)) return TRUE; else return FALSE; } //filter by size, function valid_size() { if($_FILES['uploadFile'. $x]['name']['size'] > 1048576) return FALSE; //Over one mega else return TRUE; } // check if successfully copied if($copy){ print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">"; //Writes the information to the database mysql_query("INSERT INTO `employees` VALUES ('$ID','$name', '$suburb', '$price', '$content', '$content2','$agentmobile', '$agentemail','$uploadFile0','$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')") ; } else{ echo "$file_name The File(s) could not be uploaded!<br>The file must be under 1 meg and be of a valid extension type, (jpeg, ,jpe, jpg, png or gif!<br /> <br /> Please go back and try agian"; } // end of loop ?>
From all the responses proir to this, im sure there is an answer in there somewhere, i'm a begginer and still learning.
Could some one paste the nessessary code in mine and ill see if it works.
Thanks so much
-
I added your code
<?php //This is the directory where images will be saved $path = '../images/'; //This gets all the other information from the form $name=$_POST['name']; $suburb=$_POST['suburb']; $price=$_POST['price']; $content=$_POST['content']; $content2=$_POST['content2']; $agentmobile=$_POST['agentmobile']; $agentemail=$_POST['agentemail']; $uploadFile0=($_FILES['uploadFile0']['name']); $uploadFile1=($_FILES['uploadFile1']['name']); $uploadFile2=($_FILES['uploadFile2']['name']); $uploadFile3=($_FILES['uploadFile3']['name']); $uploadFile4=($_FILES['uploadFile4']['name']); $uploadFile5=($_FILES['uploadFile5']['name']); $uploadFile6=($_FILES['uploadFile6']['name']); $uploadFile7=($_FILES['uploadFile7']['name']); $uploadFile8=($_FILES['uploadFile8']['name']); // Connects to your Database mysql_connect("localhost", "root", "5050888202") or die(mysql_error()) ; mysql_select_db("gcproperty") or die(mysql_error()) ; for($x=0;$x<$uploadNeed;$x++){ $file_name = $_FILES['uploadFile'. $x]['name']; // strip file_name of slashes $file_name = stripslashes($file_name); $file_name = str_replace("'","",$file_name); if(file_exists($path . $file_name) || !valid_ext($file_name)) { echo "The file {$file_name} already exists."; } else { $copy = move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'], $path . $file_name); } } // check if successfully copied if($copy){ print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">"; //Writes the information to the database mysql_query("INSERT INTO `employees` VALUES ('$name', '$suburb', '$price', '$content', '$content2','$agentmobile', '$agentemail','$uploadFile0','$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')") ; } else{ echo "$file_name The File(s) could not be uploaded!<br>The file must be under 1 meg and be of a valid extension type, (jpeg, ,jpe, jpg, png or gif!<br /> <br /> Please go back and try agian"; } // end of loop ?>
But now it doesnt post the files or record and i get this error
The File(s) could not be uploaded!
The file must be under 1 meg and be of a valid extension type, (jpeg, ,jpe, jpg, png or gif!
Please go back and try agian
-
Does the code need to be structured in a different order, cant seem to see what is wrong as i have no errors, just doesnt do exactly what i want.
Thanks again for everyones help
-
I added the code and made the changes, thanks everyone, i dont get errors now but the image still uploads and overwrites the old one.
Here is my full code
<?php //This is the directory where images will be saved $path = '../images/'; //This gets all the other information from the form $name=$_POST['name']; $suburb=$_POST['suburb']; $price=$_POST['price']; $content=$_POST['content']; $content2=$_POST['content2']; $agentmobile=$_POST['agentmobile']; $agentemail=$_POST['agentemail']; $uploadFile0=($_FILES['uploadFile0']['name']); $uploadFile1=($_FILES['uploadFile1']['name']); $uploadFile2=($_FILES['uploadFile2']['name']); $uploadFile3=($_FILES['uploadFile3']['name']); $uploadFile4=($_FILES['uploadFile4']['name']); $uploadFile5=($_FILES['uploadFile5']['name']); $uploadFile6=($_FILES['uploadFile6']['name']); $uploadFile7=($_FILES['uploadFile7']['name']); $uploadFile8=($_FILES['uploadFile8']['name']); // Connects to your Database mysql_connect("localhost", "root", "5050888202") or die(mysql_error()) ; mysql_select_db("gcproperty") or die(mysql_error()) ; $uploadNeed = $_POST['uploadNeed']; // start for loop for($x=0;$x<$uploadNeed;$x++){ $file_name = $_FILES['uploadFile'. $x]['name']; // strip file_name of slashes $file_name = stripslashes($file_name); $file_name = str_replace("'","",$file_name); $copy = move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'], $path . $file_name); } //filter file exists function existingfile($filename){ $files = glob("../images/*.".$extension); /////////////// line 46 if(in_array($filename, $files)) return TRUE; else return FALSE; } //filter extensions function valid_ext($file_name) { $valid = array("jpeg","jpg","jpe","png","gif"); $extension = strtolower(substr(strrchr($file_name,"uploadFile".$x),1)); if(in_array($extension, $valid)) return TRUE; else return FALSE; } //filter by size, function valid_size() { if($_FILES['uploadFile'. $x]['name']['size'] > 1048576) return FALSE; //Over one mega else return TRUE; } // check if successfully copied if($copy){ print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">"; //Writes the information to the database mysql_query("INSERT INTO `employees` VALUES ('$name', '$suburb', '$price', '$content', '$content2','$agentmobile', '$agentemail','$uploadFile0','$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')") ; } else{ echo "$file_name The File(s) could not be uploaded!<br>The file must be under 1 meg and be of a valid extension type, (jpeg, ,jpe, jpg, png or gif!<br /> <br /> Please go back and try agian"; } // end of loop ?>
-
Please help, am so confused now ???
-
I added this to my code
//filter file exists function existingfile($filename){ files = glob("../images/*.$extension"); /////////////// line 46 if(in_array($filename, $files)) return TRUE; else return FALSE; }
and i get this error
Parse error: syntax error, unexpected '=' in C:\Program Files\Apache Group\Apache2\htdocs\gcproperty\admin\add_test.php on line 46
-
See what you mean, all the files are going to be image files, jpeg, jpg, gif or png.
-
i added the code, it still uploads the files, Does it check in my ../images folder?
-
I want to filter image size, type and check if file name already exists.
Thans heaps for your help, may have this finished today after all, your the best, cant thank you enough
-
thanks, your a wizard, but how would include that code in mine, code below
<?php //This is the directory where images will be saved $path = '../images/'; //This gets all the other information from the form $name=$_POST['name']; $suburb=$_POST['suburb']; $price=$_POST['price']; $content=$_POST['content']; $content2=$_POST['content2']; $agentmobile=$_POST['agentmobile']; $agentemail=$_POST['agentemail']; $uploadFile0=($_FILES['uploadFile0']['name']); $uploadFile1=($_FILES['uploadFile1']['name']); $uploadFile2=($_FILES['uploadFile2']['name']); $uploadFile3=($_FILES['uploadFile3']['name']); $uploadFile4=($_FILES['uploadFile4']['name']); $uploadFile5=($_FILES['uploadFile5']['name']); $uploadFile6=($_FILES['uploadFile6']['name']); $uploadFile7=($_FILES['uploadFile7']['name']); $uploadFile8=($_FILES['uploadFile8']['name']); // Connects to your Database mysql_connect("localhost", "root", "5050888202") or die(mysql_error()) ; mysql_select_db("gcproperty") or die(mysql_error()) ; $uploadNeed = $_POST['uploadNeed']; // start for loop for($x=0;$x<$uploadNeed;$x++){ $file_name = $_FILES['uploadFile'. $x]['name']; // strip file_name of slashes $file_name = stripslashes($file_name); $file_name = str_replace("'","",$file_name); $copy = move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'], $path . $file_name); } //filter extensions function valid_ext($file_name) { $valid = array("jpeg","jpg","jpe","png","gif"); $extension = strtolower(substr(strrchr($file_name,"uploadFile".$x),1)); if(in_array($extension, $valid)) return TRUE; else return FALSE; } //filter by size, function valid_size() { if($_FILES['uploadFile'. $x]['name']['size'] > 1048576) return FALSE; //Over one mega else return TRUE; } // check if successfully copied if($copy){ print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">"; //Writes the information to the database mysql_query("INSERT INTO `employees` VALUES ('$name', '$suburb', '$price', '$content', '$content2','$agentmobile', '$agentemail','$uploadFile0','$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')") ; } else{ echo "$file_name The File(s) could not be uploaded!<br>The file must be under 1 meg and be of a valid extension type, (jpeg, ,jpe, jpg, png or gif!<br /> <br /> Please go back and try agian"; } // end of loop ?>
-
I have this code.
The image size filter works but not the file extension filter.
Would like a check to see if file exsists too.
Thanks for any help
//filter extensions function valid_ext($file_name) { $valid = array("jpeg","jpg","jpe","png","gif"); $extension = strtolower(substr(strrchr($file_name,"uploadFile".$x),1)); if(in_array($extension, $valid)) return TRUE; else return FALSE; } //filter by size, function valid_size() { if($_FILES['uploadFile'. $x]['name']['size'] > 1048576) return FALSE; //Over one mega else return TRUE; }
PHP File upload help
in PHP Coding Help
Posted
I just went through two weeks of hell getting my upload image page sorted, there are ppl here that can help and this is a good place to start.
Do you simply want ppl on your site to be able to upload a image?