File upload issues

software development

#1

I am trying to upload images using a form. I have the form working just like i want it to in IE, but when I attempt to upload images from netscape, firefox, or safari the image doesn’t upload. DOes anyone know if there is some setting that i need adjust or parameter i need to use? Thanks for your help.


#2

What code are you using?
Do you have an option turned off in these to stop files (unlikely in all programs and if you can do it on other sites).


#3

I am using PHP. I created the code myself so that i could rename the files to my standard naming format…here is my code:

variables:
$gif=“image/gif”;
$jpeg=“image/pjpeg”;

section of code:
if($adtype==4){
if($img1_name!=NULL){
$ext=$img1_type;
if ($ext==$gif || $ext==$jpeg){
if ($ext==$gif){
$newext=".gif";
$image1=$newImgID.$file1.$newext;
//newImgID is a variable i pull from another table
@copy("$img1" , “uploads/$image1”);
}
if($ext==$jpeg){
$newext=".jpg";
$image1=$newImgID.$file1.$newext;
@copy("$img1" , “uploads/$image1”);
}
}
else{
$badfile=“yes”;
}
}
}


Thanks for your help.


#4

I’m trying to make one myself. I’ve done it before but it doesn’t seem to like working on two different hosts so I’ve made the script wrong… You could try using else statements and using echos to see where it’s not working. It might be an actual upload error for those browsers so check $_FILES[$file_name][‘error’] for upload errors.


#5

Sorry for the double post but you might have seen my message and not replied

<?php //phpinfo(); $upload_dir = "images/"; if(isset($_FILES['file_upload']['tmp_name'])){ if(move_uploaded_file($_FILES['file_upload']['tmp_name'], $upload_dir . $_FILES['file_upload']['name'])){ echo "Uploaded file ok!
"; } else{ echo "Could not upload file
"; } } ?>

It doesn’t do any checks on what is uploaded. Try that. Thing to point out is to not use absolute paths when using defining directory to upload to.
ie $upload_dir = “images/”;
and not
$upload_dir = “/images/”;

at least I’ve figured where my scripts are going wrong at least =/


#6

I am having the same problems. None of my files will upload. I have made sure the permissions are set correctly (ie, 777). And yet, I still get the same warning messages on my upload script:

Warning: move_uploaded_file(mp3/ns bettergo 8.mp3): failed to open stream: No such file or directory in /home/.hajur/mensient/mensientertainment.com/hidden/includes/php/mp3_uploads.php on line 83

Warning: move_uploaded_file(): Unable to move ‘/tmp/php8FSUxc’ to ‘mp3/ns bettergo 8.mp3’ in /home/.hajur/mensient/mensientertainment.com/hidden/includes/php/mp3_uploads.php on line 83

$upload_dir = ‘mp3/’; // this is correct right…using a relative path?

I am uploading to my mp3 folder, which is one level down from my main web directory. Am I doing something wrong? Any help would be appreciated. And what’s funny is that every now and then, maybe 1 out 10 tries, the file will get uploaded (after looking in the folder with my FTP program), but the warning message will still be generated on the upload web page…what gives?

I’m still waiting for DreamHost Tech’s to contact me, but haven’t as of yet.



#7

Depends on your directory tree but that script should work. No checks and very easy…

I think your upload_dir might need some “…/…/mp3s/”.
I had this test script in my main directory
eg www.domain.com/test_upload.php

and so the file would get uploaded to
www.domain.com/images

It seems you’ve got your files in lots of sub folders. Try using
eg $upload_dir = “…/…/…/mp3/”;

that should get you down to your main level and the mp3 folder if your mp3 folder is like
www.domain.com/mp3


#8

Thanks for the swift reply, but that advice didn’t help. I still get the same warning message. What’s funny is although I get that warning message everytime, 1 out of 10 upload tries, I’ll check to see if the file is there with my FTP program, and it will be. It’s almost like the server’s /tmp directory is taking forever to write the file to the directory I specify.

Any other assistance?

Again, this is how my directory tree is setup:

www.domain.com/hidden/mp3.php

Inside mp3.php is a script called ‘upload_mp3.php’, which resides in:

www.domain.com/hidden/include/php/upload_mp3.php

So, in ‘upload_mp3.php’, my upload directory variable is “mp3/”;

Shouldn’t that equal to www.domain.com/mp3/ ?

Now, I tried what you suggested (ie, …/…/…/mp3/), and it still didn’t work?

I’m at my wits end here. I really need this to get fix. I do appreciate your help.

PS. Those file names are made-up names. But their location in my directory tree is legit.


#9

Ok try “…/…/mp3/” now I know how it’s all set up.

If you put a / at the front of any directories, it will look for the next folder name from the very base of the tree (this is in Unix). You would then have to go through the directory tree to find your site (maybe something like /usr/user_name/site_name/mp3). This can be very unreliable and probably won’t work.
If you leave out the / at the front of a directory tree, it will be relative from the folder you are running the script from. You can use …/ to go up a level in the directory listing.

Since you file/script is in

domain.com/hidden/include/php/

you will have to go up 2 levels to get to

domain.com/hidden/

and then access your mp3 folder

domain.com/hidden/mp3/


#10

I completely understand what you’re saying (I have used Unix for 4 years), yet the problem still persists. I have not pre-appended my upload dir variable with a forward slash.

Also, the mp3 directory is located here: www.domain.com/mp3, not www.domain.com/hidden/mp3. But still, I understood what you were saying. I applied the same principle and it is still generating the same warning messges.

Understand. The main mp3 script is here: www.domain.com/hidden/mp3.php. Inside mp3.php is the require function that includes the mp3 upload script, which is located here: www.domain.com/hidden/include/php/upload_mp3.php. So, which file would be consider the calling script? mp3.php? Or upload_mp3.php?

It really doesn’t matter because I have tested the variable in both situations and it still doesn’t work. This isn’t fair. Why isn’t this working like it is suppose to?

I mean, I have tried ‘mp3/’, ‘…/mp3/’, ‘…/…/mp3/’, ‘…/…/…/mp3/’, upwards to 7 of these things ‘…/’.

And always, this is the error message I get:
// DEBUG
Array ( [myfile] => Array ( [name] => ns bettergo 8.mp3 [type] => audio/mpeg [tmp_name] => /tmp/phpnf2toO [error] => 0 [size] => 105324 ) )

Warning: move_uploaded_file(…/…/…/…/…/…/…/mp3/ns_bettergo_8.mp3): failed to open stream: No such file or directory in /home/.hajur/mensient/mensientertainment.com/hidden/includes/php/mp3_uploads.php on line 83

Warning: move_uploaded_file(): Unable to move ‘/tmp/phpnf2toO’ to ‘…/…/…/…/…/…/…/mp3/ns_bettergo_8.mp3’ in /home/.hajur/mensient/mensientertainment.com/hidden/includes/php/mp3_uploads.php on line 83

What is going on here?



#11

Sorry. I didn’t know if you were knew to computers/hosting or not so I thought I might as well explain it.
I think it depends on where you are defining and using the $upload_dir.
If you define and use it in the mp3.php then probably just need “…/mp3/”.
If you define and use it in the include you’d need “…/…/…/mp3/”

For all my script I put a define (‘ROOT_DIR’, ‘…/’); if they are a level down from the main. I prefix this to any includes I do from them on.

This is the second problem I’ve not been able to help with today o_O. Sorry.


#12

It’s okay. I do appreciate your patience and willingness to help me out. I will figure this out some way or another. And if I find out, I’ll post my solution here.


#13

After my last post yesterday, I gave up trying to get it to work. Today, I fire up my FTP program to see if the file actually uploaded to the folder, despite the warning messages the script generated on the page…and guess what? The file is THERE!!!

This is getting beyond frustrating. Dreamhost hasn’t helped me out yet. So, I’m still waiting on them.



#14

decswxaqz,

I almost forgot about this post, but I wanted to respect my promise and tell you when the problem got fixed.

I realized all along that the information you were giving me were correct. The reason why the script continued to generate those errors was because I forgot I had an incorrect

tag in my script, which should have been edited out. Once I fix that problem, I no longer received the errors.

Thanks again for your dedication and support when I was having problems.

Peace and Blessings.


#15

Glad you got it sorted out.
Hope you got it sorted out long before now… or you wouldn’t have any hair left by now ^_^;;