Jump to content

[SOLVED] Mmmmm. My upload script that did just what I wanted it to till now???


Recommended Posts

Hey up People

 

Well I have this little script that took me ages. Basically it's an image upload but I want people to be able to Select the picture they are uploading as there default so It will appear on there profile.  Its been working for the last few days, but just gone on to show my mate today and no matter if the box is checked or not its setting the default flag ???

 

Any way here is my code

 

 

<input class="input" type="checkbox" name="default" value="default" />

 

And the PHP it posts to. I must have just deleted summat by mistake but can't I chuffin spot it

 

<?php
session_start();

$username = $_SESSION['username'];
$userid = $_GET['userid'];
$img_cap = $_POST['caption'];
$default = '0';

$host = 'localhost';
$db_username = 'root';
$db_password = '';
$db_name = 'klubdeutsch';
mysql_connect("$host" , "$db_username" , "$db_password")or die("Cannot Connect to Server");
mysql_select_db("$db_name")or die("Cannot connect to Database");


if(isset($_POST['default'])){

if($_POST['default'] == 'default'){
$default = '1';
}
}

if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)){

$filename = basename($_FILES['uploaded_file']['name']);

$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "jpg") && ($_FILES["uploaded_file"]["size"] < 350000)){

$newname = dirname(__FILE__).'/images/profilepics/'.$username.$filename;

if (!file_exists($newname)){

if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))){

if($default = '1'){
$def_img_query = "SELECT * FROM images WHERE user_id='$userid' AND def_img='1'";
$query = mysql_query($def_img_query);
$num_rows = mysql_num_rows($query);

if($num_rows != 0){

$array = mysql_fetch_array($query);
$img_id = $array['img_id'];



$remove_def_flag = mysql_query("UPDATE images SET def_img = 0 WHERE img_id='$img_id'");
}
}


$sql_update_images = mysql_query("INSERT INTO images (user_id, img_src, img_cap, def_img) VALUES ('$userid', '$username$filename', '$img_cap', '$default')")or die(mysql_error());

{
header("location:profile_test.php?userid=$userid");
}

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

 

Anyways hope you all have a good evening and happy hunting. I been looking at it for over an hour!!!!!!  >:(

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.