Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/141496-please-help-urgent/
Share on other sites

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.";

}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740629
Share on other sites

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
}
?> 

Link to comment
https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740630
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740633
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740643
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740748
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740752
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/141496-please-help-urgent/#findComment-740916
Share on other sites

  • 1 month 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.