Jump to content

help with submitting form to same url


deathadder

Recommended Posts

i have a php script and i want it to submit to itself having the php script on the same page, the problem is when i do it it tries to upload the file without waiting for the form resaulting in format you tried to upload was not allowed" (its an image uploader)

 

heres my code

<?php
   // Configuration - Your Options
      $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation.
      $max_filesize = 1524288; // Maximum filesize in BYTES (currently 1.5MB).
      $upload_path = './files/'; // The place the files will be uploaded to (currently a 'files' directory).

   $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.

   // Check if the filetype is allowed, if not DIE and inform the user.
   if(!in_array($ext,$allowed_filetypes))
      die('<font size="4"><font color="red">The file you attempted to upload is not allowed.</font></font>');

   // Now check the filesize, if it is too large then DIE and inform the user.
   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.');

   // Check if we can upload to the specified path, if not DIE and inform the user.
   if(!is_writable($upload_path))
      die('You cannot upload to the specified directory, please CHMOD it to 777.');

   // Upload the file to your specified path.
   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
         echo '<font size="4"><span style="color: white; text-shadow: lime 0px 0px 3px;"><h2>Upload Successful!</h2><br>  
<img src="' . $upload_path . $filename . '"><br>
<p id="codes"><label for="codedirect">Direct Link:</label><br />

            <input type="text" id="codebb" value="http://imageplanet.site90.net/' . $upload_path . $filename . '" onclick="javascript:this.focus();this.select();" readonly="true" /><br />
            <label for="codehtml">HTML code:</label><br />
            <input type="text" id="codehtml" value="<img src="http://imageplanet.site90.net/' . $upload_path . $filename . '">" onclick="javascript:this.focus();this.select();" readonly="true" /><br />
            <label for="codebb">IMG code:</label><br />
            <input type="text" id="codebb" value="[img=http://imageplanet.site90.net.info/' . $upload_path . $filename . ']" onclick="javascript:this.focus();this.select();" readonly="true" /></p></div>




</span></font>'; // It worked.
      else
         echo '<font size="4"><font color="red">There was an error during the file upload.  Please try again.</font</font>'; // It failed .

?>

<form action="upload.php" method="post" enctype="multipart/form-data">
   <p>
      <label for="file"><font color="white">Select a image:</font></label>
<br><br> <input type="file" name="userfile" id="file"> <br />
      <button>Click Here To Upload</button>
   <p>
<br>
<br>
<font color="#006FFF"><span style="font-family: Criovision; font-weight: normal; font-style: normal; text-decoration: none; font-size: 15pt;">Max File Upload Size: 1.5MB<br></span></font>

</div>
</span>

 

i just want it so it doesn't display that error

Link to comment
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.