Hi,
Can u please show the sample code for file upload...
thanks....
Hi,
Can u please show the sample code for file upload...
thanks....
I have since resolved this problem.
The problem was/is this:
A file for upload cannot be passed between multiple forms, which I was trying to do. The file reference is persisitent (and thus caused my confusion). However, the temporary file on the server is just that: temporary. Therefore, even though the reference to it exists, the file disappears.
David
Here is the code for uploading the picture in the first place:
<form enctype="multipart/form-data" action="picture2.php3" method=POST target="mainframe">
<input type="hidden" name="MAX_FILE_SIZE" value="50000">
Send this file:
<input name="userfile" type="file">
<input type="submit" value="Send File" name="submit">
</form>
Here is the code for the picture2.php3 script which looks after the picture renaming:
if ($userfile_size==0) {
check the picture size - if it was too big then it comes in as 0! Then display the appropriate message:
}
else
{
if (file_exists
($userfile_name))
{
It will crash if it finds a file of the same name, so in this instance I just don't allow the upload. Displays a message to that effect
}
else
{
I'm copying it rather than moving it
copy($userfile,$userfile_name);
unlink($userfile);
}
}
?>
hahaha...
Sorry, guys. I just re-read that thread.
I think my brain's turned to mush. I've spent the last couple of weeks going through heavily recursive and nested code & it's taken its toll. D'oh.
So, have you sorted this problem yet?
Hey Dave ,
Could u get the Original file name that was Uploaded into the temp Directory..
i am trying the Following code for uploading,
if(!@copy($userfile,$userfile_name))
{
echo "File Not Uploaded ";
}
else
{
echo "File Uploaded ";
}
with the above code i am not sucessfull..
But i c that the File is temporarily uploaded in to the Temporary directed if i use the following code..
if(!@copy($userfile,$userfile.".Bak"))
{
echo "File Not Uploaded ";
}
else
{
echo "File Uploaded ";
}
The File is uploaded into the Temporary Directory with Some name..
How do i get the name of the Temporary file to Original name .
Hope to hear from you soon,
Sudeep Kumar
Assuming the input box is called "inputFile"...
$originalnameoffile = "$inputFile_name";
copy($inputFile, "$inputFile_name");
copy $inputFile,"$originalnameoffile");
Don't worry about the temporary file. It'll be deleted soon-enough anyway.
Dear Dave,
Can you help me to find the location of the temporary file.
Thanks.
Hello !
I have some problems too..
First of all , even the temporary directory is set in php.ini , it writes to /home/html.
But the most important thing is that $userfile reports the original file name..
It does not upload and create the tempfile.
I run php 3.0.15 (or something like that) that came within RedHat 6.2.
Please help me !
Thank you.
Hi Lewi, Alexandru et al,
Sorry for not getting back to you all earlier.
The location for temporary files can be set in php.ini as upload_tmp_dir
By default this is commented out, but remove the semi-colon from the line, and insert the path you wish to use.
As for uploading the file and handling it, try:
copy($userfile, "members/upload/$userfile_name");
You will notice that $userfile_name actually specifies the name of the file you attepted to upload.
Just be aware that if users could potentially upload files with the same name, that you will need to sort out a unique naming convention.
Hope this helps.
David
Thank you , Dave.
I knew about the temp directory... I wrote that in my original message..
The problem came from the maximum file size option... I was in a hurry and did not pay enough attention to the manual..
Sorry ;(
Thank you again for your help.
Alex.
Thank you , Dave.
After i receiveing your email, i immediately try your suggestion. And it works perfectly.
Thanks for your help.
Lewi
im sorry i have a problem too. but not in names :-)
i have upload problem, must i open my pic directory to everyone (chmod 777) for uploading files?
No, not 777. (Trying to remember my permissions off the top of my head)...
Try 744 or 644... (no promises that they're the best settings though)
One major problem I had with file uploads was using PHP 4.0.3.pl1 which has a known bug: For all intents and purposes, you can't upload with that version without a work-around, so avoid it!
Hope this helps,
David
Hello,
Here is what I get, after submitting (trying to send file 6.jpg):
Warning: Unable to create '6.jpg': Permission denied in /home/internet/picture2.php3 on line 15
Does it mean, that there is no way for me to send file thrue web page???
I cannot modify configuration of webserver, it is not local.
Thank you for any help.
Sincerely,
Andrius
Well,the script runs on the web server and so there shudnt be any problem with the function that you are trying to do.
Any way can u paste the code that you are trying to use.
BR//
sudeep Kumar
Sounds to me like your file permissions aren't set right on the server, rather than there actually being a problem with the code.
Are you able to change the permissions?
If not, you'll have to ask your systems adminstrator to change the permissions.
Alternatively if you have telnet access, you should be able to "chmod" the directory.
Off the top of my head, 644 should be sufficient.
Hope this helps.
David
if you can not connect by telnet...
you can change your directory pemissions by ftp programs. WS_FTP or Voyager_ftp or cute_ftp are some of them. connect to your site and change that directories permissions. you must open write protect permission to the group! (not to everyone, its unsecure)...
if problems yet, please write..
Hi Elizabeth,
Did you solve the file name problem?
I'm trying to use a javascript function, but not all browser support it.
If you solved it using php, please, answer me soon.
thanks
Rodrigo Sotolani
Here we go:
In the calling 'page' it says:
<FORM ENCTYPE="multipart/form-data" ACTION="picture1.php3?lastid" METHOD=POST target="mainframe">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="50000">
Send this file: <INPUT NAME="userfile" TYPE="file">
<INPUT TYPE="submit" VALUE="Send File">
<input type="hidden" name="lastid" value="<?php echo $lastid ?>">
</FORM>
Then the file (in this case picture1.php3) has the following code
<head>
<title>Picture 1 Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<form name="form1" >
<?php
if ($userfile_size==0) {
?>
<table width="100%" dwcopytype="CopyTableRow">
<tr>
<td><font face="Arial, Helvetica, sans-serif">Your pictures file size is
too big. The limit is 50K per picture.</font></td>
</tr>
</table>
<?php
}
else
{
if (file_exists('directorypath/'.$userfile_name))
{
?>
<table width="100%" dwcopytype="CopyTableRow">
<tr>
<td><font face="Arial, Helvetica, sans-serif">Another picture using that
name exists already. Please give your image another name.</font></td>
</tr>
</table>
<?php
}
else
{
copy($userfile,'directorypath/'.$userfile_name);
unlink($userfile);
$db = mysql_connect("ourhost.net", "dbname","dbpassword");
mysql_select_db("dbname",$db);
$sql = "UPDATE TABLENAME SET PICTURE1='$userfile_name' WHERE ORGID=$lastid";
$result = mysql_query($sql);
?>
<table width="100%">
<tr>
<td>
<p><font face="Arial, Helvetica, sans-serif">File uploaded:</font></p>
<p><font face="Arial, Helvetica, sans-serif">Click Refresh on your Organization's
Details to see the new picture</font></p>
</td>
</tr>
</table>
<input type="hidden" name="lastid" value="<?php echo "$lastid" ?>">
</form>
<?php
}
}
?>
</body>
and that all worked fine for me.
Regards
Elizabeth
does this file have to be 777??? I can't get it to work any other way.
I if does, how can I set it so people can't view the source and screw with my directory?