Jump to content

Image upload through url in php


Guest phpbaby

Recommended Posts

Guest phpbaby

Hi there, i need a script to upload image to my site through a url For example if i specify the url : www.mysite.com/images/logo.jpg in the text box and submit it then the image " logo.jpg " need to be uploaded in my server. Please let me know if anyone aware about this type of script.

Link to comment
Share on other sites

alrighty I've got one for ya, it took me a while to figure out tho. it consists of two files, upload.php, and results.php.first, a few things to be aware of, the folder you wish to upload your file to must have permissions 777 (well I don't know much about permissions so I just experimented a bit and that's what I came up with, I'm sure if you research permissions you could change that number to something else if you wish).second, in upload.php, you have to set the max upload size in bytes, by default it's set to 2097152 bytes which is 2 megabytes. if you wish to adjust that number just google "# megabytes to bytes" and it will calculate it for you.by default the upload directory is "/home/DOMAIN/public_html/images/", you can change this when you go to upload a file each time or you can also set it in the upload.php code (this would be a good idea to atleast set the DOMAIN part).upload.php:

<html><head><title>Upload</title></head><body bgcolor="#FFFFFF">Max upload size: 2 megabyte (2,097,152 bytes)<!-- The data encoding type, enctype, MUST be specified as below --><form enctype="multipart/form-data" action="results.php" method="POST">    <!-- MAX_FILE_SIZE must precede the file input field -->    <input type="hidden" name="MAX_FILE_SIZE" value="2097152" />    <!-- Name of input element determines name in $_FILES array -->    Upload directory: <input name="uploaddirectory" type="text" value="/home/DOMAIN/public_html/demo/" size="50"/><br/>    Send this file: <input name="userfile" type="file" size="50"/><br/>    <input type="submit" value="Send File" /></form></body></html>

results.php:

<html><head><title>Results</title></head><body bgcolor="#FFFFFF"><?php// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead// of $_FILES.$uploaddir = $_POST['uploaddirectory'];$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);echo '<pre>';if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {   echo "File was successfully uploaded!\n";} else {   echo "Upload failed!\n";}echo "<br/><a href=\"upload.php\" title=\"Upload another\">Upload another</a>";echo 'Here is some more debugging info:';print_r($_FILES);print "</pre>";?> </body></html>

put these in the same directory. this is just what I figured out by looking aro und php.net, if you have a version of php than version 4.1.0, let me know so I can make some changes. it's pretty basic but it should do the trick. let me know how it works out for you :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...