Jump to content

Annoying Error


smc

Recommended Posts

Hey Alright well I'm trying to randomize my file name for uploaded files, but I have a problem.

When using this code:
[code]
function create_file_name($file){
$now=time();
$info=pathinfo($file);
$ext=$info['extension'];
$filename=$now; $filename.="."; $filename.=$ext;
return $filename;}

if($file_name !="")
{
if ($file_type == "application/x-msdownload" || $file_type == "audio/mpeg" || $file_type == "audio/mp3"){
    header("Location:$invalidurl");
}
else{
create_file_name("$file");
copy ("$file", "../uploaded/$filename")
    or header("Location:$errorurl");
}
}
[/code]

I get this:
[code]

Warning: copy(../uploaded/): failed to open stream: Is a directory in /home/smc/public_html/upload/uploadengine.php on line 34

Warning: Cannot modify header information - headers already sent by (output started at /home/smc/public_html/upload/uploadengine.php:34) in /home/smc/public_html/upload/uploadengine.php on line 35
[/code]

Help :'(

Thanks,
SMC
Link to comment
Share on other sites

Here I'll post the complete code.

I did update it a bit with help thanks to Orio.

[code]

Warning: copy(1146404932.): failed to open stream: No such file or directory in /home/smc/public_html/upload/uploadengine.php on line 49

Warning: Cannot modify header information - headers already sent by (output started at /home/smc/public_html/upload/uploadengine.php:49) in /home/smc/public_html/upload/uploadengine.php on line 50

[/code]

Is the new error. Here is the complete code:

[code]
<?php

///////////////////////////////////////////////////
////            PCF Upload Script              ////
////            By: SMC                        ////
////          http://smc.xeeblo.net            ////
////                v.091                      ////
///////////////////////////////////////////////////

$formurl = "/upload/";
$linkurl = "../uploaded/$file_name";
$displayurl = "/uploaded/$file_name";
$invalidurl = "/upload/invalid.html";
$nofileurl = "/upload/nofile.html";
$errorurl = "/upload/error.html";
$imagedisplay = "$linkurl";
$filesizevar = "filesize($file_name)";
$sizeerror = "/upload/sizeerror.html";

function create_file_name($file){
$now=time();
$info=pathinfo($file);
$ext=$info['extension'];
$filename=$now; $filename.="."; $filename.=$ext;
return $filename;}

/*
/////This is just a reference////////
if($file_name !="")
{
if ($file_type == "application/x-msdownload" || $file_type == "audio/mpeg" || $file_type == "audio/mp3"){
header("Location:$invalidurl");
}
else{
$filename=create_file_name($file);
if(!copy("$filename", "../uploaded/$file_name")){header("Location:$errorurl");}
else{echo('File uploaded!<br /><a href="../uploaded/'.$filename.'">Click here to see it</a>');};

////////////////////////////////////////
*/

if($file_name !="")
{
if ($file_type == "application/x-msdownload" || $file_type == "audio/mpeg" || $file_type == "audio/mp3"){
    header("Location:$invalidurl");
}
else{
$filename=create_file_name("$file");
if(!copy("$filename", "../uploaded/$file_name")){
header("Location:$errorurl");}
}
}
else {
    header("Location: $nofileurl");
    exit;
}
if($file_size > 2000000){
header("Location:$sizeerror");
}
if ($file_type == "image/jpeg" || $file_type == "image/png" || $file_type == "image/pjpeg" || $file_type == "image/gif")
{ $imagedisplay = "$linkurl";
}
else {
    $imagedisplay = "/upload/file.jpg";
}
?>
<html><center><head><title>PCF Upload Centre :: Upload Complete</title></head>
<body bgcolor="#000000" link="#465263" vlink="#465263" alink="#C0C0C0">
<center>
<img border="0" src="../upload/datauploadgfx.jpg" width="469" height="114"></center>
<table border="1" width="480" height="26">
    <tr>
        <td height="26" width="470"><b><font color="#FFFFFF" size="5">File upload succeeded...</font></b></td>
    </tr>
    <tr>
        <td height="26" width="470">
<font color="#FFFFFF"><ul>
<li>
<p align="left"><font color="#FFFFFF">Sent: <?php echo "$file_name"; ?>
<li>
<p align="left"><font color="#FFFFFF">Size: <?php echo "$file_size"; ?> bytes
<li>
<p align="left"><font color="#FFFFFF">Type: <?php echo "$file_type"; ?>
</font>
</ul>
        </td>
    </tr>
    <tr>
        <td height="26" width="470">
        <p align="center"><img src="<?php echo "$imagedisplay" ?>"></p>
        <p align="center"><font color="#FFFFFF">
</br>
<b><u><font size="4">File Address:</font></u></b><br><br>
<b><font color="#3366FF">Url:</font></b><input type="text" name="myimg" value="http://wwww.smc.xeeblo.net<?php echo "$displayurl"; ?>" onClick="highlight(this);" size="25"><b> ||</b>
        <font color="#3366FF"><b>Img:</b></font><font color="#FFFFFF"><input type="text" name="myimg" value="[IMG]http://wwww.smc.xeeblo.net<?php echo "$displayurl"; ?>[/IMG]" onClick="highlight(this);" size="25"></font></td></tr>
</table>
</body>
</center>
</html>
[/code]
Link to comment
Share on other sites

Guest askjames01
line 49 it must be wrong path directory try to replace it.
and with header place understand it it will throw some error if you begin with white space.

try to read this header();
[a href=\"http://us2.php.net/manual/en/function.header.php\" target=\"_blank\"]header()[/a]

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.



<html>
<?php
/* This will give an error. Note the output
* above, which is before the header() call */
header('Location: [a href=\"http://www.example.com/');\" target=\"_blank\"]http://www.example.com/');[/a]
?>



Note: As of PHP 4, you can use output buffering to get around this problem, with the overhead of all of your output to the browser being buffered in the server until you send it. You can do this by calling ob_start() and ob_end_flush() in your script, or setting the output_buffering configuration directive on in your php.ini or server configuration files.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.