473,387 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

cant get copy or move_uploaded_file to work

Im trying to get an image upload script to work within a session file.....i can get it to work on a single page without any other script....but i need to have the image upload facility built into a add product form....so the script is currently sitting in a session file at the same point as where the fields are all validatedd....i've tried using copy and move_uploaded_file.

I know the structure of the code is probably not great but i cant seem to find out why it wont work.

$subimgfile is the variable name for $_FILES['imgfile']['name']
and $subimgfiletype is the variable name for $_FILES['imgfile']['type']

Expand|Select|Wrap|Line Numbers
  1. if ($subimgfile)
  2. {
  3. $uploaddir = "./product_images";
  4. if (($subimgfiletype != "image/gif")  && ($subimgfiletype != "image/jpeg") && ($subimgfiletype != "image/pjpeg"))
  5.     {
  6.        $form->setError($field, "* Image Must be .jpg / .jpeg or .gif, your file had extension $subimgfiletype");
  7.         unlink($subimgfile);
  8.     }
  9.     $imgsize = GetImageSize($subimgfile);
  10.     if (($imgsize[0] > 531) || ($imgsize[1] > 398)) 
  11.     {
  12.         $tmpimg = tempnam("/tmp", "MKUP");
  13.         system("djpeg $subimgfile >$tmpimg");
  14.         system("pnmscale -xy 531 398 $tmpimg | cjpeg -smoo 10 -qual 80 >$subimgfile");
  15.         unlink($tmpimg);
  16.     }
  17. $final_filename = str_replace(" ", "_", $subimgfile);
  18. $FileCounter = 1; 
  19. while (file_exists( 'product_images/'.$final_filename )) 
  20.   $final_filename = $FileCounter++.$final_filename; 
  21.     $newfile = $uploaddir . "/$final_filename";
  22.     if (!copy($subimgfile,"$newfile")) 
  23.        {
  24.           $form->setError($field, "* Error uploading file");
  25.        }
  26.     unlink($subimgfile);
  27. }
Jun 30 '09 #1
3 2529
dlite922
1,584 Expert 1GB
You need to troubleshoot your code. I don't know what those system calls do and what tempnam() does or what you're trying to do with image facilities and add product forms.

Maybe you can describe your problem in a more technical way?

Note: you do know that $_FILES['imgfile']['name'] is only the name of the file, not where it is stored on the server, right? see $_FILES['imgfile']['tmp_name']



Dan
Jul 1 '09 #2
Hi,

Thanks for pointing that out.....i kind of knew that but still didnt realise that was my porblem....which it was sot thanks.

The only part i cant get to work now is the resizing

Expand|Select|Wrap|Line Numbers
  1. $imgsize = GetImageSize($subimgfile);
  2.     if (($imgsize[0] > 200) || ($imgsize[1] > 200)) 
  3.     {
  4.         system("djpeg $subimgfile >$subimgfiletmp");
  5.         system("pnmscale -xy 200 200 $subimgfiletmp | cjpeg -smoo 10 -qual 80 >$subimgfile");
  6.     }
$subimgfile is the $FILES['imgfile']['name'] and
$subimgfiletmp is the $FILES['imgfile']['tmp_name']

I presume this will only work for jpegs....is there a resize script that will work for both gif and jpegs....cheers.
Jul 2 '09 #3
Dormilich
8,658 Expert Mod 8TB
@ukfusion
you could try PHP’s GD library.
Jul 2 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Felix Natter | last post by:
hi, I would like to upload a file (via a form), then read that (temporary) file and write the contents into a database. The first problem is that open_basedir=/home/CUSTOMER so I can't just read...
1
by: sa | last post by:
Trying to upload a file using win xp/iis/php. I've given full access to all accounts trying to get this to work? Yet I'm still getting read errors. Simplified the script below to the bare...
6
by: Stijn Goris | last post by:
HI all, I have created a script that allows a user to upload a picture. I have an IIS server runing on my own pc but the actual site runs an Apache server. The upload script worked perfectly on...
2
by: Brian | last post by:
Hi I am moving a site to a new server, I have been testing it and one of the pages uses move_uploaded_file, but I get a Permission denied. The directory I am moving it to is chomd of 755, if...
3
by: Davide | last post by:
Hi all. I've got a simple question. Is it possible with the command "copy" upload a file via browser on two different directories? I use copy copy("$file", "/directory1/$superdat_name")
2
by: g35rider | last post by:
Hi, I have the following code that is giving this error, I cant simplify the code, I was just testing some theory for something we are doing and was getting an issue here. Please someone point out...
5
by: bill | last post by:
I can validate that the file uploaded because is_uploaded_file() returns true. --------- if (is_uploaded_file($_FILES)) { echo "File ". $_FILES ." uploaded successfully.<br />"; }...
6
by: WolfgangS | last post by:
Ok first off, i am a total beginner at this groups stuff and i have no clue how this works. This is probabaly the wrong group for my problem but i will post it anyways. Learning by doing right? ...
1
by: Sebzzz | last post by:
Hi, I have a form where user can attach a resumé and I want my script to put it in the cv folder of the server and then send me the link by e- mail. However, I tried a lot of combinations...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.