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>

  • 2 weeks later...
  • 3 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.