jamesxg1 Posted January 19, 2009 Share Posted January 19, 2009 SOMEONE PLEASE HELP I HAVE CREATED A PHP UPLOAD SCRIPT AND BASICALLY CUSTOMERS UPLOAD A PROFILE PICTURE TO MY SITE AND IT ADDS THE FIEL NAME TO A DB ROW SO I CAN SYTHER WHO UPLOADED THE IMAGE AND SO THAT MY SCRIPT CAN ASWELL. . . . WELL HERE'S MY PROBLEM. . . .I NEED THE SCRIPT TO SAVE THE EXTENSION OF THE FILE AS WELL AS IT'S NAME AND I DONT KNOW HOW TO CODE IT. . . I ALSO NEED IT TO ONLY ALLOW IMAGE FILES. . . BUT ONCE AGAIN I DONT KNOW HOW :S, HERE IS MY CODE. . . . <?php session_start(); require("../db/db.php"); //include database file require("../db/config.php"); //include configuration file require("../db/util.php"); isloggedin(); accessneeded("C"); ?> <?php //This is the directory where images will be saved $target = "images/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $pic=($_FILES['photo']['name']); // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()) ; mysql_select_db("share") or die(mysql_error()) ; //Writes the information to the database mysql_query("UPDATE users SET photo='$pic' WHERE photo=''") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "Your File ". basename( $_FILES['uploadedfile']['name']). " Has Been Uploaded!."; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file.<br>Please Retry."; } ?> IF ANYONE CAN MODIFY THIS CODE AND MAKE IT DO THEM TWO THINGS IT WOULD BE VERY VERY APPRECIATED, MANY MANY THANKS JAMES. Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/ Share on other sites More sharing options...
asmith Posted January 19, 2009 Share Posted January 19, 2009 $_FILES['uploadedfile']['name'] already includes the file extension in it. don't know why you need it. however, One way of getting it will be : <?php $file_ext = end(explode('.',$_FILES['uploadedfile']['name'])); ?> Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740628 Share on other sites More sharing options...
jamesxg1 Posted January 19, 2009 Author Share Posted January 19, 2009 OK THANKYOU HERE'S THE CODE ADDED AM I RIGHT ?, <?php session_start(); require("../db/db.php"); //include database file require("../db/config.php"); //include configuration file require("../db/util.php"); isloggedin(); accessneeded("C"); ?> <?php $file_ext = end(explode('.',$_FILES['uploadedfile']['name'])); ?> <?php //This is the directory where images will be saved $target = "images/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $pic=($_FILES['photo']['name']['$file_ext']); // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()) ; mysql_select_db("share") or die(mysql_error()) ; //Writes the information to the database mysql_query("UPDATE users SET photo='$pic' WHERE photo=''") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "Your File ". basename( $_FILES['uploadedfile']['name']). " Has Been Uploaded!."; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file.<br>Please Retry."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740629 Share on other sites More sharing options...
Zhadus Posted January 19, 2009 Share Posted January 19, 2009 Additionally, using asmith's code you can check the extension for valid filetypes: <?php $file_ext = end(explode('.',$_FILES['uploadedfile']['name'])); if (($file_ext == 'jpeg') || ($file_ext == 'jpg') || ($file_ext == 'gif') || ($file_ext == 'png')) { // All is good } else { // Bad filetype } ?> Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740630 Share on other sites More sharing options...
popcornplya Posted January 19, 2009 Share Posted January 19, 2009 Sorry this is off topic, but can you not write in CAPS? It's annoying. Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740632 Share on other sites More sharing options...
jamesxg1 Posted January 19, 2009 Author Share Posted January 19, 2009 Ok No Probs ,, And Would Anyone Be Able To Compile This For Me I Havent The Slightest ,, And This Is The Snippet From The Code Where It Add's The Info To The Database (I Think), //This gets all the other information from the form $pic=($_FILES['photo']['name']['$file_ext']); James. Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740633 Share on other sites More sharing options...
DeanWhitehouse Posted January 19, 2009 Share Posted January 19, 2009 Use code tags as well, please! Also don't put urgent in thread titles you are not more important than any one else. Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740634 Share on other sites More sharing options...
springer- Posted January 19, 2009 Share Posted January 19, 2009 Use code tags as well, please! Also don't put urgent in thread titles you are not more important than any one else. Maybe not but he has 6 replies including answers. My post from 30 minutes before his has 4 views and no replies. His methods seems to work better than mine. Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740643 Share on other sites More sharing options...
trq Posted January 19, 2009 Share Posted January 19, 2009 And Would Anyone Be Able To Compile This For Me I Havent The Slightest PHP isn't a compiled language. Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740648 Share on other sites More sharing options...
DeanWhitehouse Posted January 19, 2009 Share Posted January 19, 2009 His might be simpler to answer Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740650 Share on other sites More sharing options...
jamesxg1 Posted January 19, 2009 Author Share Posted January 19, 2009 Lol. . . . See Like I Said I Havent The Slightest Lol , Is There Anyone Who Would Be Able To Do Me A Favour. . . ?, Instead Of Using The Script I Have Made Is There Anyone Who Could Make Me One ?, All I Need It To Do Is Upload To A Directory And Then Add The Details Of The Image To A DataBase Row, I Would Muchly Apreciate It If Anyone Could Spare Me The Time To Do This For Me. . .And I Will Re-Pay The Favour In Any Way I Can ? Many Thanks James. Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740748 Share on other sites More sharing options...
DeanWhitehouse Posted January 19, 2009 Share Posted January 19, 2009 Post in the freelance section for that, or google it, or even better learn how to do it using online tutorials and trial and error Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740751 Share on other sites More sharing options...
trq Posted January 19, 2009 Share Posted January 19, 2009 Lol. . . . See Like I Said I Havent The Slightest Lol , Is There Anyone Who Would Be Able To Do Me A Favour. . . ?, Instead Of Using The Script I Have Made Is There Anyone Who Could Make Me One ?, All I Need It To Do Is Upload To A Directory And Then Add The Details Of The Image To A DataBase Row, I Would Muchly Apreciate It If Anyone Could Spare Me The Time To Do This For Me. . .And I Will Re-Pay The Favour In Any Way I Can ? Many Thanks James. This forums primary purpose is for helping people who are learning php with there coding problems. If your looking for a script to be written for you, read our freelance boards rules then post your request there. This is not the place. Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740752 Share on other sites More sharing options...
jamesxg1 Posted January 19, 2009 Author Share Posted January 19, 2009 Ok. No Probs Cheerz For Letting Me Know , Do You Have The Link Handy ?, Many Thanks James. Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740760 Share on other sites More sharing options...
trq Posted January 19, 2009 Share Posted January 19, 2009 Start here. Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740764 Share on other sites More sharing options...
jamesxg1 Posted January 19, 2009 Author Share Posted January 19, 2009 Thankyou. And Thankyou Everyone For Your Help!, Your All Star's!. James. Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740771 Share on other sites More sharing options...
jamesxg1 Posted January 20, 2009 Author Share Posted January 20, 2009 If Anyone Is Still Viewing This Thread, Can Anyone Help Me With The Extension Problem I Have Thats The Main Thing I Need The Most. Many Many Thanks James. Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740910 Share on other sites More sharing options...
haku Posted January 20, 2009 Share Posted January 20, 2009 This section of the forum is for helping people with troubles they are having with scripts they are writing themselves. It's not for helping people with 3rd party scripts, or for finding freelancers (there is another section of the forum for those two things). As such you are posting in the wrong section. Also, starting every word with a capital letter, using italics, forgetting code tags, and putting 'urgent' in the thread title are all forum faux-pas. Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740916 Share on other sites More sharing options...
angus930 Posted March 1, 2009 Share Posted March 1, 2009 Whats with the capitals? Its annoying as all hell you know that. Quote Link to comment https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-773643 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.