Reply to in need of some solution...

Your name:

Reply:


Posted by Kentor on 07/28/06 01:30

Hello, I have a website to list vacation rentals and housings. I want
to be able to modify images after a user has submitted their listing
with/without images.
How it works: the first time they submit their listing, they enter all
the info and then add any images onto a field by browsing to the image.
They can have up to 7 images. Once the person is done I have two fields
in my database "pics" and "ext" pictures are to set the number of
pictures for this listing and ext are the extensions for each picture.
The ext field goes something like this: jpg.bmp.jpg. and pics would be
3. the way the files are stored are by post id, so for example if the
post id is 192 then images would be 192_0.jpg 192_1.bmp and 192_2.jpg.
Ok now, i need to find some way to allow people to delete or change the
images or upload images if they dont have any at all.... I need to
somehow display the already existing images, and then check each field
to see if its empty or not and somehow concatinate with the existing
images or something. After the function is executed, a simple update
statement is needed.
I just get lost in all of this. Any help will be greatly appreciated.

Here is my function to upload files

function uploadFiles()
{

$postnumber = $this -> postnum;
$counter = 0;

// before we bother doing anything, check permissions on the upload
directory, try to set
if ( substr(sprintf('%o', fileperms(UPLOADDIR)), -4) != '0777' ) {
// attempt to set the image dir to 777
if ( ! @chmod(UPLOADDIR, 0777) ) {
$this -> errorString .= "Directory permissions for
\"'.UPLOADDIR.'\" not valid.'. <br />";
die('Unable to fix directory permissions, you will have to do this
manually. (Needs: chmod 0777 '.UPLOADDIR.')'."<br />\n");
}
}
// check the at least one filefield exists
if ( !isset($_FILES[FILEFIELD]) ) die('No files detected in
upload.'."<br />\n");

// begin looping through the file upload fields
foreach ($_FILES[FILEFIELD]['error'] as $key => $upload_error) {
// check if the upload is ok
if ($upload_error == UPLOAD_ERR_OK) {
$upload_name = strtolower($_FILES[FILEFIELD]['name']["$key"]);
$upload_type = $_FILES[FILEFIELD]['type']["$key"];
$upload_size = $_FILES[FILEFIELD]['size']["$key"];
$upload_tmpname = $_FILES[FILEFIELD]['tmp_name']["$key"];
$upload_ext = '';

$valid_types = explode(',', VALIDTYPES);
// check if the type is valid
if ( !in_array($upload_type, $valid_types) ) {
$this -> errorString .= "Invalid file type: ";
$this -> errorString .= $upload_name;
$this -> errorString .= ", the file must be .jpg .jpeg .gif .png
or .bmp<br />";
return false;
} else {
// make sure to grab the filename extension
// messy. should be done with regex or something
$upload_ext = explode('.', $upload_name);
$upload_ext = strtolower($upload_ext[count($upload_ext)-1]);
}
// check if the size if valid
if ( $upload_size > MAXFILESIZE ) {
$this -> errorString .= "File too large. It must be less than
500KB (512 000 bytes)<br />";
return false;
}

$upload_filename = $postnumber.'_'.$counter.'.'.$upload_ext;
// move the file
if ( move_uploaded_file($upload_tmpname,
UPLOADDIR.$upload_filename) ) {
$this -> imageExt .= $upload_ext.'.';
$counter = $counter + 1;

} else {
$this -> errorString .= "Unable to move file to
\".UPLOADDIR.$upload_filename.\"<br />";
return false;
}
}
}

$this -> imageCounter = $counter;
return true;
}

the class has an "include("upload_Housingconf.php");" at the top

and this file looks like this:

<?php

define('FILEFIELD', 'picture');

define('UPLOADDIR', 'housingImages/');

define('MAXFILESIZE', 512000);
define('ENCRYPT_FILENAME', false);
define('MAXENCFILELENGTH', 50);
define('VALIDTYPES',
'image/gif,image/jpg,image/pjpeg,image/jpeg,image/x-png,image/png,image/bmp');
?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация