Jump to content

replace browse button to fixed file and auto submit


Recommended Posts

Hello,

 

I want to change this script for admin use.

What i want is that you dont have to browse for an image, but is set to the dir where the image to be uploaded is. For example www.mysite.com/folder

 

Also, if possible, i want an auto sumit.

 

The idea is that an admin can call this script on a admin section of the website (that is no problem at all) and that the image will be uploaded automaticly.

 

Can anyone help me out ?

 

Thanks in advance,

 

 

Greetings, Jack

<html>
<form enctype="multipart/form-data"
action="<?print $_SERVER['PHP_SELF']?>" method ="post">

<tr><td><input type = "hidden" name="MAX_FILE_SIZE" value = "102400"></td></tr>
<tr><td>Select File: </td><td><input type = "file" name = "fupload"><t/d></tr>
<tr><td><input type = "submit" value = "Upload!"></td></tr>
</table>
<?php
//checking and uploading file-----------------------------------------------------------
if (isset ($_FILES['fupload'])){

$filename = $_FILES['fupload']['name'];
$randomdigit = rand(0000,9999);//create random digit
$newfilename = $randomdigit.$filename;//make new file name with random digit

//printing file information
print "<table>";
print  "<tr><td>Original Name:</td><td> ". $_FILES['fupload']['name']."</td></tr>";
print	"<tr><td>New Name:</td><td> ".$newfilename."</td></tr>";
print  "<tr><td>Size: </td><td>". $_FILES['fupload']['size']."</td></tr>";
print  "<tr><td>Temp Name: </td><td>". $_FILES['fupload']['tmp_name']."</td></tr>";
print  "<tr><td>Type: </td><td>". $_FILES['fupload']['type']. "</td></tr>";
print  "<tr><td>Error: </td><td>". $_FILES['fupload']['error']. "</td></tr>";
print "</table>";


//checking the type of file, if it is image it will display it
if ($_FILES['fupload']['type'] == "image/jpeg"){
$source = $_FILES['fupload']['tmp_name'];
$target = "upload/".$_SESSION['username']."/".$newfilename;
move_uploaded_file($source, $target); // or die ("Couldnt copy");


//displaying the image
$imagesize = getImageSize($target);
$imgstr = "<p><img width=\"$size[0]\" height=\"$size[1]\" ";
$imgstr .= "src=\"$target\" alt=\"uploaded image\" ></p>";

$imagepath = $yoursite.$target;

print $imgstr;
print "The link to your image is: ".$yoursite.$target;//link to the image


}
}
//-------------------------------------------------------------------------------------
?>
</html>

Link to comment
Share on other sites

  • 2 weeks later...

<form name="upload" enctype="multipart/form-data"

action="<?php print $_SERVER['PHP_SELF']; ?>" method ="post">

 

 

<input type = "file" name = "fupload" onpropertychange="if(event.propertyName=='value') {document.upload.submit();}">

Link to comment
Share on other sites

  • 3 weeks later...
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.