PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
i have spent all day tryin go to get this to work and some one may be able to help.
i making a dynamic website and i want the customer to register and beable to upload an image like an avatar (also for stock photo)
i have made a simple form where a user enters information such as name etc and browse for a photo. I then insert the information into myPHPmyadmin database. I have no idea what to do with the photo!
i have read lots of tutorials and i am confused about where the image is stored and how to recall it.
im using phpmyadmin 2.9.2 fillzilla
thank you Huh
i know you have to store the path well i just dont have a clue
when you upload a file it is automaticaly stored in a temporary directory on the server
then using the function below it is moved into the directory you want.
the code for uploading files is..
hi thank you for replying i have just tryed to tutorial in the tutorial section and have no joy im not sure if it uploading and i just dont kno where it is as it comes back with a white screen! how can i find out my directory address (are these the files on fillazilla?)
you have just uploaded a file called 'picture 1.jpg'
the temporary directory it is saved in is '/tmp/phfwqrbr'
what you need to is move the file from there to where ever you want, we'll call this folder '/my folder/'.
so with the function moveuploaded_file($temp_directory, $new_directory)
try using this code:
FYI to the OP, phpMyAdmin is an administrator interface to your MySQL database. It is not a database in and of itself. Also, when you upload the image, after you have moved it, you are going to want to store the path in the database. The image however should be stored on the file system.
<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>
<?php
print "<pre>";
print_r($_FILES);
print "</pre>";
// Get the details of "imagefile"
$filename = $_FILES['imagefile']['name'];
$temporary_name = $_FILES['imagefile']['tmp_name'];
$mimetype = $_FILES['imagefile']['type'];
$filesize = $_FILES['imagefile']['size'];
//Open the image using the imagecreatefrom..() command based on the MIME type.
switch($mimetype) {
case "image/jpg":
case "image/jpeg":
$i = imagecreatefromjpeg($temporary_name);
break;
case "image/gif":
$i = imagecreatefromgif($temporary_name);
break;
case "image/png":
$i = imagecreatefrompng($temporary_name);
break;
}
//Delete the uploaded file
unlink($temporary_name);
//Save a copy of the original
imagejpeg($i,"images/uploadedfile.jpg",80);
//Specify the size of the thumbnail
$dest_x = 150;
$dest_y = 150;
//Is the original bigger than the thumbnail dimensions?
if (imagesx($i) > $dest_x or imagesy($i) > $dest_y) {
//Is the width of the original bigger than the height?
if (imagesx($i) >= imagesy($i)) {
$thumb_x = $dest_x;
$thumb_y = imagesy($i)*($dest_x/imagesx($i));
} else {
$thumb_x = imagesx($i)*($dest_y/imagesy($i));
$thumb_y = $dest_y;
}
} else {
//Using the original dimensions
$thumb_x = imagesx($i);
$thumb_y = imagesy($i);
}
//Generate a new image at the size of the thumbnail
$thumb = imagecreatetruecolor($thumb_x,$thumb_y);
//Copy the original image data to it using resampling
imagecopyresampled($thumb, $i ,0, 0, 0, 0, $thumb_x, $thumb_y, imagesx($i), imagesy($i));
//Save the thumbnail
imagejpeg($thumb, "images/thumbnail.jpg", 80);
$new_directory = 'my folder'.$_FILES['name'];
move_uploaded_file($_FILES['imagefile']['tmp_name'], $new_directory);
?> </form>
</body>
</html>
here is all of my code! its proberly something really simple but i would love to get it working!