Jump to content

image upload help


imarockstar

Recommended Posts

Ok guys .....

 

 

Here is what I got :

 

I have 2 scripts running 1) registration script 2) image upload script. Both are working, however I need them to work together.

 

The registration script does just that, gathers new users info and places it into a database. The image upload scrip uploads the image into a directory called /upload/.

 

What i need is for the script to also input the location of the file into the database so it will show on the users page. I am not sure how to tell the registration scrip the location of the image that has been uploaded. Below is the code.

 

link to site:  http://www.themyspacecontest.com/newsite/signup.php

 

// Collect the data from post method of form submission // 
$userid=$_POST['userid'];
$password=$_POST['password'];
$password2=$_POST['password2'];
$agree=$_POST['agree'];
$todo=$_POST['todo'];
$email=$_POST['email'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$phone=$_POST['phone'];
$zipcode=$_POST['zipcode'];
$pmsid=$_POST['pmsid'];
$cmsid=$_POST['cmsid'];


?>
<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>(Type a title for your page here)</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>

<body >
<?
if(isset($todo) and $todo=="post"){

$status = "OK";
$msg="";

// if userid is less than 3 char then status is not ok
if(!isset($userid) or strlen($userid) <3){
$msg=$msg."User id should be =3 or more than 3 char length<BR>";
$status= "NOTOK";}					

if(!ctype_alnum($userid)){
$msg=$msg."User id should contain alphanumeric  chars only<BR>";
$status= "NOTOK";}					


if(mysql_num_rows(mysql_query("SELECT userid FROM plus_signup WHERE userid = '$userid'"))){
$msg=$msg."Userid already exists. Please try another one<BR>";
$status= "NOTOK";}					

if(mysql_num_rows(mysql_query("SELECT email FROM plus_signup WHERE email = '$email'"))){
$msg=$msg."This email address is there with us. If you forgot your password you can activate it by using forgot password link. Or Please try another one<BR>";
$status= "NOTOK";}					

if ( strlen($password) < 3 ){
$msg=$msg."Password must be more than 3 char legth<BR>";
$status= "NOTOK";}					

if ( $password <> $password2 ){
$msg=$msg."Both passwords are not matching<BR>";
$status= "NOTOK";}					


if ($agree<>"yes") {
$msg=$msg."You must agree to terms and conditions<BR>";
$status= "NOTOK";}	

if($status<>"OK"){ 
echo "<font face='Verdana' size='2' color=red>$msg</font><br><input type='button' value='Retry' onClick='history.go(-1)'>";
}else{ // if all validations are passed.
$password=md5($password); // Encrypt the password before storing

if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
  //Check if the file is JPEG image and it's size is less than 350Kb
  $filename = basename($_FILES['uploaded_file']['name']);
  $ext = substr($filename, strrpos($filename, '.') + 1);
  if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") && 
    ($_FILES["uploaded_file"]["size"] < 350000)) {
    //Determine the path to which we want to save this file
      $newname = dirname(__FILE__).'/upload/'.$filename;
      //Check if the file with the same name is already exists on the server
      if (!file_exists($newname)) {
        //Attempt to move the uploaded file to it's new place
        if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
           echo "It's done! The file has been saved as: ".$newname;
        } else {
           echo "Error: A problem occurred during file upload!";
        }
      } else {
         echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
      }
  } else {
     echo "Error: Only .jpg images under 350Kb are accepted for upload";
  }
} else {
echo "Error: No file uploaded";
}

if(mysql_query("insert into plus_signup(userid,password,email,fname,lname,phone,zipcode,pmsid,cmsid) values('$userid','$password','$email','$fname','$lname','$phone','$zipcode','$psmid','$cmsid')")){

echo "<font face='Verdana' size='2' color=green>Welcome, You have successfully signed up<br><br><a href=login.php>Click here to login</a><br></font>";
}else{
echo "<font face='Verdana' size='2' color=red>There is some database problem, Please contact site admin<br><br><a href=login.php>Click here to login</a><br></font>";

}
}
}
?>

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/104039-image-upload-help/
Share on other sites

      if (!file_exists($newname)) {
        //Attempt to move the uploaded file to it's new place
        if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
          //insert a MySQL Query to add the directory and filename to the DB $newname is the full location
          // of your file.  Not sure how your server is setup, but you may need to have just "/upload/".$filename
          // get sent to your DB. 
           echo "It's done! The file has been saved as: ".$newname;
        }

 

Hope that helps!

Link to comment
https://forums.phpfreaks.com/topic/104039-image-upload-help/#findComment-532588
Share on other sites

I actually tried that first and i t did work . however .. I need it inserted to to the same record as the other posts (the ones at the top).

 

If I add a query were you said then it will add a separate record.

 

Basically the photo is the avatar of the person registering so i need it in the same row so when I call there information I can call there photo as well.

 

b

Link to comment
https://forums.phpfreaks.com/topic/104039-image-upload-help/#findComment-532787
Share on other sites

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.