LemonInflux Posted August 28, 2007 Share Posted August 28, 2007 Basically, I need a code that will upload images to a directory on my server, and when a user submits a picture, a link to the picture is returned to them. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/67150-simple-image-uploader/ Share on other sites More sharing options...
matthewhaworth Posted August 28, 2007 Share Posted August 28, 2007 Basically, I need a code that will upload images to a directory on my server, and when a user submits a picture, a link to the picture is returned to them. Any ideas? Good some tutorials. We are not here to write code. Quote Link to comment https://forums.phpfreaks.com/topic/67150-simple-image-uploader/#findComment-336779 Share on other sites More sharing options...
Fadion Posted August 29, 2007 Share Posted August 29, 2007 If u want just some directions then: - Make a form with a: enctype="multipart/form-data" and a file field - Use $_FILES for file names, size etc - Use move_uploaded_file() to upload the file in your directory - Return the file name u set it. If u want a script that works then i can write a simple one for u. Quote Link to comment https://forums.phpfreaks.com/topic/67150-simple-image-uploader/#findComment-336782 Share on other sites More sharing options...
LemonInflux Posted August 29, 2007 Author Share Posted August 29, 2007 Just the script. This isn't for me to learn anything, I just need it quick. I'll write a better one myself some other time. Quote Link to comment https://forums.phpfreaks.com/topic/67150-simple-image-uploader/#findComment-336784 Share on other sites More sharing options...
Jessica Posted August 29, 2007 Share Posted August 29, 2007 Google...there are tons. Quote Link to comment https://forums.phpfreaks.com/topic/67150-simple-image-uploader/#findComment-336787 Share on other sites More sharing options...
Fadion Posted August 29, 2007 Share Posted August 29, 2007 jesirose and matthewhaworth have it right, as this isnt a request forum, instead a learning one. Anyway as this was quick and easy, here u go: <form enctype="multipart/form-data" name="myform" method="post" action=""> <input type="file" name="file" /> <input type="submit" name="Submit" value="Submit" /> </form> <?php if($_FILES['file']['name'] != ""){ $filename = $_FILES['file']['name']; $ext = strtolower(substr(strrchr($filename, '.'), 1)); $imagesExt = array('jpg', 'jpeg', 'png', 'gif', 'bmp'); $newPath = "mynewdir/{$filename}"; if(move_uploaded_file($_FILES['file']['tmp_name'], $newPath)){ echo "File was uploaded succesfully<br />"; if(in_array($ext, $imagesExt)){ echo "Here is the image u uploaded"; echo "<img src=\"{$newPath}\" />"; } }else{ echo "There was an error uploading the file"; } } ?> Not tested though. If it has any syntax errors (missing " or ; or } or whatever) try debugging it yourself. Quote Link to comment https://forums.phpfreaks.com/topic/67150-simple-image-uploader/#findComment-336790 Share on other sites More sharing options...
LemonInflux Posted August 29, 2007 Author Share Posted August 29, 2007 Cheers. Just wrote my own, actually. Haven't tested, but if it doesn't work, I'll try yours. Quote Link to comment https://forums.phpfreaks.com/topic/67150-simple-image-uploader/#findComment-336803 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.