Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/73750-php-file-upload-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372136
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372142
Share on other sites

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);
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372144
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372152
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372156
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372699
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372967
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/73750-php-file-upload-help/#findComment-372975
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.