unlink() error

A

Anonymous

Guest
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.
 
Alicia said:
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.


Code:
unlink("../../shopping_cart1/myfol/images/".$_FILES['uploadFile'.$x]['tmp_name']);
		echo $error;

hi you can't do the above thing as the uploaded file does go into the specified directory in the php.ini file and not where you've mentioned unless thats the set dir!!

you need to copy/move the file to the images folder before deleteing it!
:)
 
hi guys,

is that mean i have to check where actually my temp folder is from ini file and then put the location to the unlink() ???

is that mean i should not put the location that i copy my image to in unlink() ??

please advise.
 
Alicia said:
hi guys,

is that mean i have to check where actually my temp folder is from ini file and then put the location to the unlink() ???

is that mean i should not put the location that i copy my image to in unlink() ??

please advise.

i doubt you will be having the permission to delete the file in the temp delete folder.. but that is what you can delete...

and yes you can't delete the file which is not present, and you should first copy the file and then unlink!!
:idea:
but why copy it and then delete :D
 
but i thought after i copied the file to a directory i want, then i need to delete the temporary file (from the temp folder).. am i right ??

or after i copied the file to a folder, the temp file will be deleted by itself ???


please advise.
 
I believe the file would be automatically deleted after the page has finished loading hence temporary file.
 
Back
Top