PDA

View Full Version : Image Upload


craigeves
03-02-2010, 02:36 PM
Is anyone able to help? I am new to PHP and MySQL - but have got fairly far in using the dreamweaver PHP functionality but am now stuck.

I want to be able to:

Upload image to server
Rename the image to that of the MM_Username (the logged in user).

It would also be good to set the maximum width and filesize of the image too.

Is anyone able to help?

Thanks in advance.

Craig

davidj
03-02-2010, 03:30 PM
I cant help with DW code but you may want to learn how to code with PHP

tux
03-02-2010, 05:25 PM
Welcome to DW Club Craig,

I used to use DW wizards and soon ran into problems and struggled to get help.

DavidJ suggested to me once that I should learn to code and very good advice it turned out to be. I wouldn't say I was great at it yet but am well on my way. I have found that hand coding my own scripts is much easier than I thought, they are much smaller than the huge lines of code the DW creates to do the same job and I can get them to do what I want them to do.

There are some tutorials (http://www.dreamweaverclub.com/vtm/php-mysql-apache.php) on this website that would get you started (produced by DJ), loads of help and advice on this forum and if you ask him I'm sure DJ would teach you. He offers lessons here (http://codezenith.co.uk/).

If I was you I would take DJs advice and take the plunge, its easier than you think.

Regards, Paul

craigeves
03-02-2010, 07:33 PM
OK - I managed to get the script to upload and rename - but it knocks off the file extension. Can anyone help me in how to add the file extension and also limit which file extensions can be uploaded?

See below.

Thanks in advance



mysql_select_db($database_user, $user);
$query_Recordset1 = "SELECT * FROM users";
$Recordset1 = mysql_query($query_Recordset1, $user) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

// Your file name you are uploading
$file_name = $HTTP_POST_FILES['ufile']['name'];

// random 4 digit to add to our file name
// some people use date and time in stead of random digit
$renamed_file_name = $row_Recordset1['username'];

//combine random digit to you file name to create new file name
//use dot (.) to combile these two variables

$new_file_name=$renamed_file_name;

//set where you want to store files
//in this example we keep file in folder upload
//$new_file_name = new upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "upload/".$new_file_name;
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>";

//$new_file_name = new file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$new_file_name."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";
}
else
{
echo "Error";
}
}

mysql_free_result($Recordset1);
?>