I use the following code to take an image from a form (imagefile) and upload it into the destination directory. It then makes a copy of the image and is meant to resize it so I have a thumbnail and a standardized version of the same image.
I have two issues with this code:
if ($imagefile!=""){
// Take uploaded file and move to destination directory
$uploaded_file = $CFG->site_root."/media/uploadedfiles/".$my_index.".jpg";
if( !copy($imagefile, $uploaded_file) ) echo "Error: could not process image file you tried to upload!!";
// Resize image
$destination_small_file = $CFG->site_root."/media/objects/prefix".$my_index."_small.jpg";
$destination_large_file = $CFG->site_root."/media/objects/prefix".$my_index."_large.jpg";
// passthru("/usr/X11R6/bin/convert -geometry 70x70 $uploaded_file $destination_small_file");
// passthru("/usr/X11R6/bin/convert -geometry 400x400 $uploaded_file $destination_large_file");
@copy($uploaded_file, $destination_small_file);
@copy($uploaded_file, $destination_large_file);
unlink("$uploaded_file");
}
- The files are uploaded sucessfully but cannot be overwritten. The owner of the uploaded file is different to that when I FTP files to my webspace, therefore if I need to overwrite these files nothing happens. I know this is due to the permissions, since if I download them using my FTP package, delete the files on the web server, re-upload them I can then replace them using my upload code. So my first question is how do I go about setting them to be overwritable on the initial upload.
This kind of brings me onto my second question.
- I am unable to run passthru commands on my webserver any longer (I don't have rights to amend this), therefore you may notice the comments I have had to implement in the code. This has meant that I can't run chown commands to change the owner, or use the convert command to resize my thumbnails. Meaning that both thumbnail and original are the same size... not ideal.
Does anyone have any ideas how I can (a) set the owner on my uploaded files so that I can overwrite them without having to use a separate FTP program, and (b) get aroung the resize images problem without having to use convert on a passthru command?
Many Thanks in Advance!