Page 1 of 1
Please help...yes images.... yes im blonde
Posted: Wed Mar 28, 2007 3:59 pm
by holz_bee
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

Posted: Wed Mar 28, 2007 4:14 pm
by coombesy
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..
Code: Select all
move_uploaded_file($tempdirectory, $directory_you_want)
more can be found at...
http://ie2.php.net/features.file-upload
you can skip most of the page... just look at example 38.2 in that page.
try running this bit of code and seeing if their are any errors.
place it in the page your form is pointing to, ie: <form post="my_upload_page.php">
so at the top of my_upload_page.php write
Code: Select all
print "<pre>";
print_r($_FILES);
print "</pre>";
post back the results.
Posted: Wed Mar 28, 2007 4:50 pm
by holz_bee
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?)

Posted: Wed Mar 28, 2007 4:59 pm
by coombesy
to find out more info in the page that the form points to place the code above
Code: Select all
<?php
print "<pre>";
print_r($_FILES);
print "</pre>";
?>
if you try that, with the results i'll be able to explain all. Gettin late where i am so i'll try tomorrow.
Posted: Wed Mar 28, 2007 5:06 pm
by holz_bee
Code: Select all
Array
(
[imagefile] => Array
(
[name] => Picture 1.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpfWQRbR
[error] => 0
[size] => 15571
)
)
this appears! is that any help?
Posted: Wed Mar 28, 2007 5:16 pm
by coombesy
yep, thats it...
Code: Select all
Array
(
[imagefile] => Array
(
[name] => Picture 1.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpfWQRbR
[error] => 0
[size] => 15571
)
)
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:
Code: Select all
$new_directory = '/my folder/'.$_FILES['name'];
move_uploaded_file($_FILES['imagefile']['tmp_name'], $new_directory);
this should work, make sure you've created the folder 'my folder' or whatever name you use

Posted: Wed Mar 28, 2007 5:24 pm
by RobertGonzalez
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.
Posted: Thu Mar 29, 2007 1:46 am
by holz_bee
Hi thank you for you replys!
i have posted the code at the end of my php script and still dont think its working!
Code: Select all
Array
(
[imagefile] => Array
(
[name] => Picture 1.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpIguxtU
[error] => 0
[size] => 15571
)
a tmp_name still appears and there is no image in the file i have created on my server
Code: Select all
<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!
Posted: Thu Mar 29, 2007 5:58 am
by impulse()
Check the permissions on the directory you're trying to move to.