General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 19th, 2003, 01:45 AM
Alicia Alicia is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 117 Alicia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 29 sec
Reputation Power: 6
unlink() error

Hi guys,

i am having some prob with my file uploading code and hope u guys may able to tell me whats wrong with my code

my uploading file is in
public_html/shopping_cart2/upload/upload.php

whereas the location i wanna upload the images is
public_html/shopping_cart1/myweb/images/

when i try to upload, it does copied the file to images folder but there is an error shown..

the message displayed =>

logo2.jpg | uploaded sucessfully!


Warning: unlink(../../shopping_cart1/myfol/images/): Is a directory in /home/eonenet/public_html/shopping_cart2/upload/processFiles.php on line 27
Error: is not supported. This system only support GIF and JPEG type format images.


my code:
<?
$uploadNeed = $_POST['uploadNeed']; // for multiple uploading
// start for loop

for($x=0;$x<$uploadNeed;$x++)
{
if($_FILES['uploadFile'. $x]['size'] > 30000)
{
$error = "Error: <b>".$_FILES['uploadFile'.$x]['name']."</b> is too large.<br> Your file is ".$_FILES['uploadFile'.$x]['size']."b. You are only allowed to upload files below 30000b (30kb)";
unlink("../../shopping_cart1/myfol/images/".$_FILES['uploadFile'.$x]['tmp_name']);
echo $error;
exit();
}

if($_FILES['uploadFile'. $x]['size'] = 0)
{
$error = "Error: <b>".$_FILES['uploadFile'.$x]['name']."</b> is not valid.<br> Your file is ".$_FILES['uploadFile'.$x]['size']."b. You are only allowed to upload files below 30000b (30kb)";
unlink("../../shopping_cart1/myfol/images/".$_FILES['uploadFile'.$x]['tmp_name']);
echo $error;
exit();
}

$ext = strtolower(strstr($_FILES['uploadFile'.$x]['name'],"."));
if($ext != ".gif" && $ext != ".jpg" && $ext !=".jpeg")
{
$error = "Error: <b>".$_FILES['uploadFile'.$x]['name']."</b> is not supported. This system only support GIF and JPEG type format images.";
unlink("../../shopping_cart1/myfol/images/".$_FILES['uploadFile'.$x]['tmp_name']);
echo $error;
exit();
}

$file_name = $_FILES['uploadFile'. $x]['name'];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
$copy = copy($_FILES['uploadFile'. $x]['tmp_name'], "../../shopping_cart1/myfol/images/$file_name");
// check if successfully copied

if($copy)
{
echo "$file_name | uploaded sucessfully!<br><br>";
}
else
{
echo "$file_name | could not be uploaded!<br><br>";
}
} // end of loop

?>


Line 27 is the part where if the type of file is not supported, unlink the temporary file... since it has been copied to the folder i want, why it still got this error ?? did i use the unlink function correctly ??

by the way, is the temporary file is stored in the images folder i wanna save or the location where my upload.php file located ?? why it works fine when i copied the image into the same folder in upload.php file (before insert the ../../shopping... string in the unlink() ) but not working after i amend the code in order to copy to other folder ?

please advise.

Reply With Quote
  #2  
Old December 19th, 2003, 08:29 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
The error message indicates that you're trying to unlink a directory, which won't work. That would seem to suggest that the filename isn't coming across correctly to the unlink() command. Try printing out the string you're passing to unlink() and make sure everything's coming across.

Reply With Quote
  #3  
Old December 21st, 2003, 09:07 PM
Alicia Alicia is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 117 Alicia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 29 sec
Reputation Power: 6
hi guys,

how can i do that ?? i mean how can i actually print out the string that i am passing to unlink ??? is there anyway i can check what parameter i should put in my unlink function ???


please advise.

Leong

Reply With Quote
  #4  
Old December 22nd, 2003, 03:59 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Print it out the same way you pass it:

PHP Code:
print "../../shopping_cart1/myfol/images/".$_FILES['uploadFile'.$x]['tmp_name']; 


If your variables aren't coming across correctly, printing them out will show you and you'll know to make adjustments in how you retrieve your variables.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > unlink() error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT