Jump to content

Php uploader script Need help


Mancent

Recommended Posts

Ok this script works but it needs to do more.

I need to resize the images that get uploaded to 300px to 300px because the images are way to big and then i need to add a if statement to send back to flash if the file is to small to upload so it will look best. so no file that is less then 300px by 300px can be uploaded.

 

this script is doing two things

One it uploads the picture to some username folder

Two it inserts into the database where username.

<?php
include "../php/connect.php";


$username = $_POST['username'];
$username = stripslashes($username);
$username = mysql_real_escape_string($username);




if(@!empty($_FILES))
{	

$_FILES['Filedata']['name'] = Relocate(utf8_decode($_FILES['Filedata']['name']),$username);



	$filepath = getcwd()."/".$_GET['dir']."/";
		if(!file_exists($filepath)) mkdir($filepath,0777);
		chmod($filepath,0777);

		if(move_uploaded_file($_FILES['Filedata']['tmp_name'], $filepath . $_FILES['Filedata']['name'])) chmod($filepath.$_FILES['Filedata']['name'], 0777);


}

function Relocate($str,$username)
{
   
   $filename = "UserPhoto.jpg";//md5($str);
   
   $setavatar = mysql_query("UPDATE accounts SET avatar = 'http://wiistream.net/users/$username/images/$filename' WHERE username = '$username'");
   
   echo '&msgText=' . $username . ''; 
   return $filename; 

}
Relocate($str,$username);





?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/218215-php-uploader-script-need-help/
Share on other sites

ok i redid the whole thing. but now I am having a problem with update mysql

<?php
include "../php/connect.php";
include('Resize.php');
//What user is online using this?
$username=$_POST['username'];
$username=stripslashes($username);
$username=mysql_real_escape_string($username);
//Ok get the user folder location
$filepath=getcwd()."/".$_GET['dir']."/";
$filetempname=$_FILES['Filedata']['tmp_name'];
$filename=$_FILES['Filedata']['name'];
$insert =(md5($filename));
//Ok let resize thie image to be small	
$image=new SimpleImage();
$image->load($filetempname);
$image->resize(300,300);
$image->save($filepath . $insert);
//lets update the database where this users photo is
$setavatar=mysql_query("UPDATE accounts SET avatar = 'http://wiistream.net/users/$username/images/$insert' WHERE username = '$username'");	
?>

 

the database updates all the information but one.

http://wiistream.net/users/Mancent/images/

 

 

the $insert is not working for the mysql but the $insert is needed to clean up spaces in images names.

 

 

 

so this should be

http://wiistream.net/users/Mancent/images/some md5 code

 

But it is adding every thing to the correct folder and naming it right for any user its just not injecting into the Database correctly

 

 

 

Ok the code above is working, but it dose  a strange thing.

 

the md5 code post 2 different codes

 

in mysql it post

d41d8cd98f00b204e9800998ecf8427e

 

and the file where it was uploaded to the folder it post

da75bf56aba6127e87731c45b40aa21b

 

How can this get fixed?

 

I know i can write some string and this would be solved

$insert ="usersphoto.jpg";

 

this would solve the problem but I want to be able to upload many images and they are all different names so md5 seemed good.

 

 

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.