class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
$folder="/domains/mysite.com/public_html/main/staff/images/pets/";
if(ftp_chmod($conn_id, 0777, $folder)) {
// we create an instance of the class, giving as argument the PHP object
// corresponding to the file field from the form
// All the uploads are accessible from the PHP object $_FILES
$handle = new Upload($_FILES['my_field']);
// then we check if the file has been uploaded properly
// in its *temporary* location in the server (often, it is /tmp)
if ($handle->uploaded) {
// yes, the file is on the server
// below are some example settings which can be used if the uploaded
// file is an image.
$handle->file_new_name_body = $_POST["name"];
$handle->image_resize = true;
$handle->image_y = 60;
$handle->image_ratio_x = 100;
$handle->image_convert = 'jpg';
$handle->jpeg_quality = 80;
// now, we start the upload 'process'. That is, to copy the uploaded file
// from its temporary location to the wanted location
// It could be something like $handle->Process('/home/www/my_uploads/');
$handle->Process("".$folder."");
// we check if everything went OK
if ($handle->processed) {
// everything was fine !
ftp_chmod($conn_id, 0755, $folder);
ftp_close($conn_id);
header("Location: true.php");
exit;
} else {
$errors= $handle->error;
mail('mymail@mysite.com','errors',$errors);
ftp_chmod($conn_id, 0755, $folder);
ftp_close($conn_id);
// one error occured
header("Location: false.php");
exit;
}
}
}
I think the error is in the /tmp directory that I don't have. Is the directory that you talk about in your commented code:
// then we check if the file has been uploaded properly
// in its *temporary* location in the server (often, it is /tmp)
The /tmp directory is set in your php.ini. If you don't have a tmp directory, then you won't be able to upload at all.
The class doesn't try to create the temporary directory. It merely uses it. PHP, for security reason, uploads the file itself into this temp directory, from which is is available to the class (is_uploaded_file() and move_uploaded_file())
I would recommend checking if a simple bit of upload code works, so to make sure that your hosting allows uploads. You can find such code there: http://www.php.net/features.file-uploadReply
Re: Destination directory can't be created. Can't carry on a process new!
I think the error is in the /tmp directory that I don't have. Is the directory that you talk about in your commented code:
Can you help me?
Thank you
The class doesn't try to create the temporary directory. It merely uses it. PHP, for security reason, uploads the file itself into this temp directory, from which is is available to the class (is_uploaded_file() and move_uploaded_file())
I would recommend checking if a simple bit of upload code works, so to make sure that your hosting allows uploads. You can find such code there: http://www.php.net/features.file-upload
It was working fine but all of a suddon i get the same error. i have changed nothing in the php files.