Mancent Posted November 9, 2010 Share Posted November 9, 2010 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 More sharing options...
BlueSkyIS Posted November 9, 2010 Share Posted November 9, 2010 i would use getimagesize() to get the image dimensions. if too small, send an error back to Flash. if okay, resize as needed. There are 1.6 million tutorials on PHP image resizing on the web, give or take 1.599 million. Link to comment https://forums.phpfreaks.com/topic/218215-php-uploader-script-need-help/#findComment-1132311 Share on other sites More sharing options...
Mancent Posted November 9, 2010 Author Share Posted November 9, 2010 ya I read them and tried many but nothing was working it still uploaded and no errors but it never resized. Thats why I thought I would has here to see if some one could solve my problem. Link to comment https://forums.phpfreaks.com/topic/218215-php-uploader-script-need-help/#findComment-1132313 Share on other sites More sharing options...
BlueSkyIS Posted November 9, 2010 Share Posted November 9, 2010 i would post code so we can try to see where you're going wrong. Link to comment https://forums.phpfreaks.com/topic/218215-php-uploader-script-need-help/#findComment-1132334 Share on other sites More sharing options...
Mancent Posted November 9, 2010 Author Share Posted November 9, 2010 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 Link to comment https://forums.phpfreaks.com/topic/218215-php-uploader-script-need-help/#findComment-1132375 Share on other sites More sharing options...
Mancent Posted November 9, 2010 Author Share Posted November 9, 2010 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. Link to comment https://forums.phpfreaks.com/topic/218215-php-uploader-script-need-help/#findComment-1132387 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.