sign guy Posted October 18, 2007 Share Posted October 18, 2007 Hello, I hope this is the correct place for this question. I was curious if anyone could help me out, I am trying to get my "Request a quote" form to be setup to where my customers can not only insert there information as far as type of sign, color,quantity and layout but also have a browse button so that they can upload a logo or specific layout already designed on there computer to me. If anyone could lend a hand in getting this page running or some helpful tips I would appreciate it. Here is the link to the page http://www.westcoastvinylsigns.com/quote.php I setup my contact form and I guess I could copy that form but I would still need help getting the upload script working. Thanks in advance The sign guy Quote Link to comment https://forums.phpfreaks.com/topic/73750-php-file-upload-help/ Share on other sites More sharing options...
simcoweb Posted October 18, 2007 Share Posted October 18, 2007 There's a file upload tutorial in the PHP Freaks tutorial section. Check that out first. Quote Link to comment https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372129 Share on other sites More sharing options...
emediastudios Posted October 18, 2007 Share Posted October 18, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372133 Share on other sites More sharing options...
sign guy Posted October 18, 2007 Author Share Posted October 18, 2007 Thats it. Not a required field but an option to the customer that is requesting a price quote. If he or she has a log image or layout they would have the option to upload that file along with there price quote request. Then I would download it from my upload_file folder. Quote Link to comment https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372136 Share on other sites More sharing options...
PHP_PhREEEk Posted October 18, 2007 Share Posted October 18, 2007 There are several very good upload classes available using PEAR. Do a Google search on pear upload class and have a look. I have used a few of those scripts rather successfully. They are very easy to modify for just about any use. Once you have selected a script to work with, we can help you customize it for your specific intent. Best, PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372142 Share on other sites More sharing options...
emediastudios Posted October 18, 2007 Share Posted October 18, 2007 you are probably like me and just want an easy solution But with a upload you need and would want filters to insure that the uploaded files didnt overright images in your folder of the same name, not exceed a certain file size and be of a valid image or file format. I have a code that i use, maybe you could pick some out of it. <?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 $copied = 0;//the number of files successfully uploaded 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); $copied++;//increment our counter } } } // check if successfully copied if($copied == $uploadNeed) { 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372144 Share on other sites More sharing options...
sign guy Posted October 18, 2007 Author Share Posted October 18, 2007 Thank you for all the help. Now forgive me for the lack of knowledge in this but what would I have to do to say the code above in order for it to work correctly on my site? Quote Link to comment https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372145 Share on other sites More sharing options...
emediastudios Posted October 18, 2007 Share Posted October 18, 2007 can you post your upload file code and you php process file code. If not me the genuis's on this site will help you better. Quote Link to comment https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372147 Share on other sites More sharing options...
simcoweb Posted October 18, 2007 Share Posted October 18, 2007 You could use something like this. It's difficult to just 'give' you a turnkey snippet since your HTML, folder setup, etc. needs to be factored in. This snippet also includes a sample upload form at the bottom, validates the file type, size, etc. and places it in the proper folder you designate. if(isset($_POST['upload']) { $ServerRoot = $_SERVER['DOCUMENT_ROOT']; // Grabs the home directory of your hosting. $Directory = 'uploads/'; // Folder that will be uploaded to relative to the public_html. $MaxFileSize = '10240'; // Maximum file size allowed. $AllowedFiles = array(jpg,gif,png,psd,zip,rar,bmp); // The allowed file extensions $FileExtension = $_FILES['file']['type']; $FileSize = $_FILES['file']['size']; $FileName = $_FILES['file']['name']; if($FileSize > $MaxFileSize) { echo 'Your file is too big!'; exit; } if(!in_array($FileType) { echo 'You are not allowed to upload that file type!'; exit; } $UploadFile = move_uploaded_file($_FILES['file']['tmp_name'], $ServerRoot$Directory); if($UploadFile !== TRUE) { echo 'Problem uploading!'; exit; } echo "File uploaded successfully: http://www.your-domain/'.$Directory$_FILES['file']['name']."; } else { echo " <form name='upload' encrypte='multipart/form-data' action="'.$_SERVER['PHP_SELF'].'" method='post'> "; echo "<input type='upload' name='file' size='30' />"; } ?><form enctype="multipart/form-data" action="upload.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> Choose a file to upload: <input name="uploaded_file" type="file" /> <input type="submit" value="Upload" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372152 Share on other sites More sharing options...
sign guy Posted October 18, 2007 Author Share Posted October 18, 2007 ok well im getting somewhere I can see an upload and I can browse for files http://www.westcoastvinylsigns.com/upload.php I know now that I have to direct where the files are to go on the server and im sure there are some more things to do like doing it the right way. Quote Link to comment https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372156 Share on other sites More sharing options...
sign guy Posted October 18, 2007 Author Share Posted October 18, 2007 Is there something I need to setup in my control panel or database? Quote Link to comment https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372328 Share on other sites More sharing options...
sign guy Posted October 18, 2007 Author Share Posted October 18, 2007 You could use something like this. It's difficult to just 'give' you a turnkey snippet since your HTML, folder setup, etc. needs to be factored in. This snippet also includes a sample upload form at the bottom, validates the file type, size, etc. and places it in the proper folder you designate. if(isset($_POST['upload']) { $ServerRoot = $_SERVER['DOCUMENT_ROOT']; // Grabs the home directory of your hosting. $Directory = 'uploads/'; // Folder that will be uploaded to relative to the public_html. $MaxFileSize = '10240'; // Maximum file size allowed. $AllowedFiles = array(jpg,gif,png,psd,zip,rar,bmp); // The allowed file extensions $FileExtension = $_FILES['file']['type']; $FileSize = $_FILES['file']['size']; $FileName = $_FILES['file']['name']; if($FileSize > $MaxFileSize) { echo 'Your file is too big!'; exit; } if(!in_array($FileType) { echo 'You are not allowed to upload that file type!'; exit; } $UploadFile = move_uploaded_file($_FILES['file']['tmp_name'], $ServerRoot$Directory); if($UploadFile !== TRUE) { echo 'Problem uploading!'; exit; } echo "File uploaded successfully: http://www.your-domain/'.$Directory$_FILES['file']['name']."; } else { echo " <form name='upload' encrypte='multipart/form-data' action="'.$_SERVER['PHP_SELF'].'" method='post'> "; echo "<input type='upload' name='file' size='30' />"; } ?><form enctype="multipart/form-data" action="upload.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> Choose a file to upload: <input name="uploaded_file" type="file" /> <input type="submit" value="Upload" /> </form> Would you be able to help me as far as factoring in my php folder setup and everything. Quote Link to comment https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372699 Share on other sites More sharing options...
sign guy Posted October 18, 2007 Author Share Posted October 18, 2007 well it appears i mihgt be on my own on this one. if anyones reading this here is what comes up when i hit upload http://www.westcoastvinylsigns.com/cgi-bin/serverinfo.cgi Quote Link to comment https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372746 Share on other sites More sharing options...
PHP_PhREEEk Posted October 19, 2007 Share Posted October 19, 2007 My original offering above still stands... there's no need to re-invent the wheel. It's already available. PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372958 Share on other sites More sharing options...
sign guy Posted October 19, 2007 Author Share Posted October 19, 2007 I appreciate your help the only thing that went wrong was if i had logo.jpg uploaded then another customer uploaded the same file it would overright it and I didnt no how to fix that. For now I got this until i learn php a little better to make this page look a little cleaner. also I couldnt get the upload.php link to fit the text within the box it kinda goes off to the left a little but thats ok for now http://www.westcoastvinylsigns.com/quote.php the upload link is on the right. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372967 Share on other sites More sharing options...
PHP_PhREEEk Posted October 19, 2007 Share Posted October 19, 2007 The classes that are available have options built in to handle your problems... really.... no re-invention necessary. All files can be given unique filenames, etc... : shrug : features you probably didn't even realize you wanted are in there. heh Well, good luck man = )) PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372975 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.